Write a void recursive function and a non-void recursive function that computes the sum of the first n integers in an array of at least n integers.
Explanation / Answer
The idea A recursive process is a process that calls itself. To calculate 1·2 ·3 ºn, here is a process that works: If n = 1 then the answer is 1. If n > 1 then Get the answer for 1·2 ·3 º(n-1) Multiply this by n. Step 1 above gives a way for the process to end. Otherwise it will go on forever. Step 2 is called the Recursive Step, the place where the process calls itself. Here it is as a function in C++: int Multiply1ThruN (int N) { int answer = 0; if (N == 1) answer = 1; //Exit step else if (N > 1) answer = Multiply1ThruN (N - 1) * N; //Recursive step return answer; } 1.2 How it works in computer memory If we call the above function with the statement: cout