ackermann function using recursive c 2b 2b

Solutions on MaxInterview for ackermann function using recursive c 2b 2b by the best coders in the world

showing results for - "ackermann function using recursive c 2b 2b"
Isabelle
14 May 2020
1#include <iostream>
2//AYAT ULLAH IIUC
3using namespace std;
4
5int ack(int m, int n)
6{
7    if (m == 0){
8        return n + 1;
9    }
10    else if((m > 0) && (n == 0)){
11        return ack(m - 1, 1);
12    }
13    else if((m > 0) && (n > 0)){
14        return ack(m - 1, ack(m, n - 1));
15    }
16}
17
18int main()
19{
20    int ans,m,n;
21    cout<<"Enter the M and N with space :";
22    cin>>m>>n;
23    ans = ack(m, n);
24    cout << ans << endl;
25    return 0;
26}
27