next up previous
Next: Recurse again Up: Assignment 5: Recursion Previous: 99 Bottles

Recurse

1.
Create a new project called Recurse.prj, again based on the cs151HelloStationery.

2.
The Ackerman function is defined for non-negative integers as follows:


\begin{displaymath}A(m,n) = \left\{
\begin{array}{l@{\quad {\mathbf if} \quad }l...
..., n=0 \\
A(m-1, A(m, n-1)) & m>0, n>0 \\
\end{array} \right.
\end{displaymath} (1)

Write a method called ack that takes two ints as parameters and that computes and returns the value of the Ackerman function.

3.
Test your implementation of Ackerman by invoking it from main and printing the return value. Warning: the return value gets very big very quickly. You should try it only for small values of m and n (not bigger than 3).



Allen B. Downey
1999-10-06