Lesson goal: Carl Gauss: Adding lists of numbers

Previous: Study the absolute value | Home | Next: Adding numbers to find Pi

There is a famous legend of a student misbehaving in class back in the late 1700s. For punishment, the teacher made him add up all of the number between 1 and 100. To the teacher's surprise, the student did it in seconds. The student was the (now) famous mathematician Carl Gauss. For loops can easily add up sequences of numbers. Let's repeat Gauss's punishment here with a for loop. Gauss's famous formula for adding numbers from $1$ to some number $a_n$ is $S_n=n(1+a_n)/2$. This formula might be in your math book.

Now you try. Use a for loop and a separate variable called sum to add up the numbers between 1 and 100.

Type your code here:


See your results here: