Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: ackermann.cpp // Compute Ackermann function values #include unsigned int A (unsigned int m, unsigned int n) { // POST: return value is the Ackermann function value A(m,n) if (m == 0) return n+1; if (n == 0) return A(m-1,1); unsigned int param = A(m, n-1); return A(m-1, param); } int main() { std::cout << "Compute Ackermann function A (m, n) for\n"; std::cout << "m = ? "; unsigned int m; std::cin >> m; std::cout << "n = ? "; unsigned int n; std::cin >> n; std::cout << "Function value is " << A(m,n) << "\n"; return 0; }