Sum of numbers: Loops

Nov 14, 2014 at 5:55am
Write a loop that calculates the sum of the numbers 21, 22, 23, .., 39. The sum is to be
written out after the loop terminates.

I'm stuck on as to how to start this, can someone help me with the base of the loop?
Last edited on Nov 14, 2014 at 5:57am
Nov 14, 2014 at 6:04am
Does the loop start at 21 and end at 39? If so, you could use a for loop that starts are 21 and ends at 39. Just use one variable to increment through the loop and another variable to hold the sum.
Last edited on Nov 14, 2014 at 6:11am
Nov 14, 2014 at 6:08am
Forget the sum. Write a for-loop that prints those numbers.
Topic archived. No new replies allowed.