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:

The code will not run as is! You have to look carefully at the for i=, do line and fix it to cause the variable i to run between 1 and 100. Can you do it? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.