104k views
1 vote
Give a recursive algorithm for finding the sum of the
first n odd positive integers.

User MS Berends
by
9.5k points

1 Answer

3 votes
I'm writing that in some sort of pseudocode; if you don't understand it, feel free to ask for more details in the comments.

function sumOdd(n)
if n==1 then
return 1
end if
return (sumOdd(n-1))+(n*2-1)
end function
User Jordan Hudson
by
9.0k points