Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Get quick and reliable solutions to your questions from a community of experienced professionals on our platform. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

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