This question was posted a few months ago, but I do not understand the answers given by the users, and was therefore wondering if anyone could explain it as simply as possible please?
Many thanx, Clare 🙂
FUNCTION Recurse(N:Integer):Integer;
If N = 1 THEN
Output 1, 1
Recurse = 1
ELSE
Output N and N(N+1)/2
Recurse = N(N+1)/2+Recurse(N-1)
END IF
END Recurse
a) Write down the output when the function is called with
i) Output, 'The answer is: ', Recurse(1)
ii) Output, 'The answer is: ', Recurse(5)
b) The function is called with Recurse(3). Produce a diagram showing each step of the algorithm and the function calls
c) Rewrite the recursive algorithm as an iterative algorithm