Answers for "ackermann function using recursive c++"

C++
0

ackermann function using recursive c++

#include <iostream>
//AYAT ULLAH IIUC
using namespace std;

int ack(int m, int n)
{
    if (m == 0){
        return n + 1;
    }
    else if((m > 0) && (n == 0)){
        return ack(m - 1, 1);
    }
    else if((m > 0) && (n > 0)){
        return ack(m - 1, ack(m, n - 1));
    }
}

int main()
{
    int ans,m,n;
    cout<<"Enter the M and N with space :";
    cin>>m>>n;
    ans = ack(m, n);
    cout << ans << endl;
    return 0;
}
Posted by: Guest on October-04-2021

Code answers related to "ackermann function using recursive c++"

Browse Popular Code Answers by Language