How do I find a recursive algorithm for finding the sum of the first n positive integers?
procedure sum of integers (n: positive integer)
else sum:=n+ sum of (n-1)
That's what I have so far, but it still doesn't make sense to me.
Chris, your algorithm is correct but is not recursive, which appears to be a requirement of the assignment based on the OP. (I could be wrong about this.)
So here is a recursive version, in no particular programming language--
Jennifer, you had the right idea in your original post, you just need to make your algorithm a little more programming-like. I generalized your algorithm a little by allowing for a sum of the first 0 integers; the sum is 0.Code:function f(n) if n = 0 then return 0 else return n + f(n-1)