Skip to content

Recursive Addition

Samem

Asked May 29, 2006, 11:29 AM EDT2 answers
Share
LinkedInX
Hi,

Does any1 here know how find out the sum of number?

Example: given number 5

i want to find out the sum of 5
1+2+3+4+5=15

how can i get it done?
sorry, am not able to put it in words properly.
Thanks in advance

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    use the formula sum=n(n+1)/2
    where n is the number for which u want to find the sum.

    is this what u r expecting?
    0
  • 0
    Use a for loop from 1 to the number, or use a while loop with a counter.
    Accumulate the value of the counter variable to the total inside the loop:
    inum = inum + i
    0