0

Somebody have the Ackerman code, i couldn't find it to run it on c++

Ackerman code

1st May 2017, 11:32 PM
juan esquivel
juan esquivel - avatar
3 odpowiedzi
+ 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)); }
2nd May 2017, 12:44 AM
⏩▶Clau◀⏪
⏩▶Clau◀⏪ - avatar
+ 2
thanks claudio that is helpful
2nd May 2017, 12:45 AM
juan esquivel
juan esquivel - avatar
0
i ment somebody can post the code
1st May 2017, 11:33 PM
juan esquivel
juan esquivel - avatar