CS210 Lab: Recursion Postlab
Postlab Exercise:
Use the following function to answer Questions 1 and 2.
int Puzzle (int base, int limit)
{
if (base > limit)
return -1;
else
if (base == limit)
return 1;
else
return base* Puzzle(base+1, limit);
}
- Identify the following:
- the base case(s) of the function Puzzle
- the general (recursive) case(s) of the function
Puzzle
- Show what would be written by the following calls to the recursive
function Puzzle
- cout << Puzzle(20,5);
- cout << Puzzle(3,6);
- cout << Puzzle(8,8);
Answer for post lab
Back to Recursion Lab click
here
Copyright: Department of Computer Science, University of Regina.