Answer :

Answer:

Please check explanation

Explanation:

// Ackermann's Function - Totally Recursive

#include<stdio.h>

#include<stdlib.h>

int ackermannfunction(int a1, int b1);

int count1 = 0, indent1 = 0;

int main(int argc, char **argv)

{

int a1,b1;

 if(argc!=3)

 {

  printf("\nUsages : %s \n",argv[0]);

  exit(0);

 }

        a1=atoi(argv[1]);  

b1=atoi(argv[2]);

       printf("\n Ackermann method with provided parameters (%d,%d) is %d\n",a1,b1,ackermannfunction(a1,b1));

      printf("\n Method called %d number of times.\n",count1);

}

int ackermannfunction(int a1, int b1)

{

count1++;

 if(a1)  return -1;

if(a1==0)

 return b+1;

if(b1==0)

 return ackermannfunction(a1-1,1);

return ackermannfunction(a1-1,ackermannfunction(a1,b1-1));

}

Other Questions