Adding Values with a For Loop

Write a program that gets an integer from the user. Add up all the numbers from 1 to that number, and display the total. Use a for loop to do it.

You have done something like this before.

Number: 5

1 2 3 4 5
The sum is 15.

 

Number: 8
1 2 3 4 5 6 7 8
The sum is 36.



©2013 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License