求指教,死循环,递归
运行之后死循环了,而且调用次序一直是1.。。怎么搞的#include<stdio.h>
int ackerman(int m,int n);
int main(void)
{
int result,m,n;
printf("please input m and n:");
scanf("%d%d",&m,&n);
result=ackerman(m,n);
printf("result=%d",result);
return 0;
}
int ackerman(int m,int n)
{
int callindex=1;
if(m==0)
{
printf("调用次序:");
printf("%d",callindex);
callindex++;
printf(" m=%d n=%d",m,n);
printf("\n");
return n+1;
}
else if(m!=0&&n==0)
{
printf("调用次序:");
printf("%d",callindex);
callindex++;
printf(" m=%d n=%d",m,n);
printf("\n");
return ackerman(m-1,1);
}
else if(m!=0&&n!=0)
{
printf("调用次序:");
printf("%d",callindex);
callindex++;
printf(" m=%d n=%d",m,n);
printf("\n");
return ackerman(m-1,ackerman(m,n-1));
}
else
return -1;
}