Forum Moderators: open
n
(this funny
M lying on its side) = n* (n+1)
i=1 2
Here's my code for the formula, does anyone know why it doesn't work?
public class Gaus extends Object {
public static void main (String args()) {
short n;
short i = 0;
short result;
n = 10; //the first 10 numbers
for
System.out.println("the sum of numbers
1 to 10 = " + result);
}
}
And now I have to find the results for "n" in this table:
n= result
10
128
150
300
70000
Please help me, I'm an absolute beginner and this stuff is just way over my head!
thanx
M*
There may be two issues here:
1. What is the Gauss Formula
2. How to write the Java for it
I assume you're talking about Gauss's formula for the sum of the first n integers (the sideways M is a sigma, or sum sign). The formula for that sum is n*(n+1)/2. Not too complicated (Gauss figured it out in third grade!)
But that's as far as I can go; Java is a foreign country to me. Maybe a java jockey will come along and take this the rest of the way for you.
Also, check out this site:
[ugrad.math.ubc.ca...]