# Math Help - Recursive Algorithm

1. ## Recursive Algorithm

Question: Give a recursive algorithm for finding the sum of the first n positive integers.

procedure sum(n: nonnegative integers)
if n = 0 then sum(n):=1
else sum(n) := sum(??)

I am not sure how to find the sum of the previous integer and add it to the next. Any help is greatly appreciated!

2. Originally Posted by Ramin_Shahab
Question: Give a recursive algorithm for finding the sum of the first n positive integers.

procedure sum(n: nonnegative integers)
if n = 0 then sum(n):=1
else sum(n) := sum(??)

I am not sure how to find the sum of the previous integer and add it to the next. Any help is greatly appreciated!
Code:
function sum(n)

if n==1
return 1
else
return n+sum(n-1)
endif

endfunction
RonL