//File:   AckermansFunction
//Author: Jesse D
//Date:   Feb. 26, 2007
//
//Description: This program uses a recursive function to calculate appropriate
//             values for Ackermans function. Since Ackermans function is 
//             itself recursivley defined, setting up the function to return
//             n is straight forward. A table is printed with the results.
//
              
#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int f(int m , int n){
       
        if (m == 0) //m is zero, return the value of n
        return (n+1);
        
        else if (n == 0) // recursive call case n = 0.
        return (f(m-1,1));
        
        else 
        return (f(m-1,f(m,n-1))); //Recursive call.
         }                         
               
int main()
{
    int m =0 , n=0; 
 
  //Print the table to the screen  
  for  (m =0; m < 4;){
    for (n =0; n < 4;){
   
  cout << setw(4) << f(m,n);
  n++;
  }
  cout << endl;
  m++;
}
  
  return 0;  
}