0
Somebody have the Ackerman code, i couldn't find it to run it on c++
Ackerman code
3 Réponses
+ 2
Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
A(m,n) = { n+1 if m=0 ;
A(m-1,1) if m>0 & n=0;
A(m-1, A(m,n-1) ) if m>0 & n>0}
#include<stdio.h>
#include<stdlib.h>
int ackermann(int x, int y);
int count = 0, indent = 0;
int main(int argc, char **argv)
{
int x,y;
if(argc!=3)
{
printf("\nUsage : %s <number1> <number2>\n",argv[0]);
exit(0);
}
x=atoi(argv[1]);
y=atoi(argv[2]);
printf("\nAckermann Function with inputs (%d,%d) is %d\n",x,y,ackermann(x,y));
printf("\nFunction called %d times.\n",count);
}
int ackermann(int x, int y)
{
count++;
if(x<0 || y<0)
return -1;
if(x==0)
return y+1;
if(y==0)
return ackermann(x-1,1);
return ackermann(x-1,ackermann(x,y-1));
}
+ 2
thanks claudio that is helpful
0
i ment somebody can post the code