Question: Give a recursive algorithm for finding the sum of first npositive integers. Show all of your work. Hint: Use the formulan(n + 1) / 2
Give a recursive algorithm for finding the sum of first npositive integers. Show all of your work. Hint: Use the formulan(n + 1) / 2
Here is my work so far
Define sum(n) by
sum(1) = 1
sum(n + 1) = sum(n) + n, where n >1
Algorithm
Procedure sum (n: positiveinteger)
if (n = 1)
sum(n) = 1
else
n := n + sum(n – 1)
I got this answer from thetextbook but it does not use the formula above. Is there anotherway to do this with the formula?
Step by Step Solution
3.45 Rating (155 Votes )
There are 3 Steps involved in it
Answer and step by step explanation Algorithm Procedure sum n positiveinteger if n 1 ... View full answer
Get step-by-step solutions from verified subject matter experts
