Ackermann

The function called Ackermann founded of Wilhelm Ackermann is a quickly growing mathematical function which shows the limit of calculable functions with primitve recursion in computers.

main.cpp
1/*
2    
3    ackermann.cpp
4    
5    How to compile with GCC under LINUX/UNIX:
6    g++ -o ackermann ackermann.cpp
7    
8*/
9
10#include <iostream>
11using namespace std;
12
13int ackermann(int, int);
14
15int main(int argc, char **argv) {
16    int m;
17    int n;
18
19    cout << "Ackermann algorithmus" << endl;
20    cout << "Enter first number: ";
21    cin >> n;
22    cout << "Enter second number: ";
23    cin >> m;
24
25    cout << "Result: " << ackermann(n,m) << endl;
26
27    return 0;
28}
29
30int ackermann(int n, int m) {
31    if(n == 0) return m + 1;
32    if(m == 0) return ackermann(n - 1, 1);
33    return ackermann(n - 1, ackermann(n, m - 1));
34}