Site hosted by Angelfire.com: Build your free website today!

Program #20
C++

Program #20

C++

K. Dzwonkiewicz

 

 

 

 

Using a for… loop to find a sum

 

Part 1

a program to find the sum of numbers in a certain range…

 

·        Ask the starting value

·        Ask the ending value

 

Print out the sum.

 

Like this…

 

Please enter start of range: 20

Please enter end of range: 75

 

 

Output:

Sum of numbers in the range 20-75 is 2660

 

 

Hint: use long int

Use one or two “for… loops” adding as you go

 

 


Part 2

Determine the sum of squares of numbers in a range

 

 

Please enter start of range: 1

Please enter end of range: 8

 

 

Output:

Sum of the squares: 1^2 + 2^2 + 3^2 + 4^2 + 5^2 + 6^2 + 7^2 + 8^2 = 204