CIS 067 Section 1
Assignment Number 09-F2001
A Simple Recursion Problem
Reading: Read Chapter 12, Sections 12.1 12.3 in the Friedman/Koffman Text.
Problem (modifying the factorial function) We developed an algorithm for recursively computing the factorial n! of a non-negative integer n. For this assignment, you will implement this function and a driver program to test your function. A few changes may be needed along the way.
A. Add three new data items (integer variables):
new_n = n 1;
factorial (new_n);
new_n = n 1;
value_returned = factorial (new_n);
return n * value_returned;
B. Next, insert print statements into your program as follows:
~~~~~ Factorial function entered at level = ð
where ð represents the value of level and is increased by one each time the function is entered (just prior to printing this line).
We have now returned to level ð ;
The value_returned = m
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C. Test your function with driver program that calls factorial with level = 0 and n = 4.
Turn In: E-mail your final program to the lab assistant.