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

Bonus #2C++

K. DZWONKIEWICZ

 

 

 

 

 

In mathematics there are some formulas first determined by Karl Friedrich Gauss to find the sum of numbers in a sequence.

 

Sum of consecutive integers: 1 + 2 + 3 + … + n = n(n+1)/2

            (n is the amount of terms)

Sum of odds: 1 + 3 + 5 + … + (2n-1) = n^2

            (n is the amount of terms.  I.e. 4th term is 2(4) – 1 or 7 and so on.)

 

Determine a formula for your program, without a loop, that will find the sum of n even numbers.

 

Hint:  Combine the two given formulas into one but watch your n value.  Sum of consecutive integers minus the sum of the odds will give the sum of evens.

 

Sample output…

Please enter how many even numbers to sum (starting point is 2): 6

Sum of the first 6 even numbers is: 42