Originally Posted by
jennifer1004 How do I find a recursive algorithm for finding the sum of the first n positive integers?
procedure sum of integers (n: positive integer)
if n:=1
then sum:=1
else sum:=n+ sum of (n-1)
That's what I have so far, but it still doesn't make sense to me.
You can do this (modify the code to the proper syntax you need):
Code:
...
sum = 0; // initialize sum
count = 1; // initialize counter
while count <= n do
sum = sum + count;
count = count + 1;
end do;
return sum;
...
Does this make sense?