Explore Westonci.ca, the leading Q&A site where experts provide accurate and helpful answers to all your questions. Join our Q&A platform to connect with experts dedicated to providing precise answers to your questions in different areas. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.

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


Sagot :

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