递归5-7
result = factorial(n-1)*n;这句代码到底是怎么运行的,没看懂,结果不应该啊20吗?
#include <stdio.h>
int factorial(int n)
{
int result;
if(n<0)
{
printf("输入错误!\n");
return 0;
}
else if(n==0||n==1)
{
result = 1;
}
else
{
result = factorial(n-1)*n;
}
return result;
}
int main()
{
int n = 0;
printf("%d的阶乘=%d",n,factorial(n));
return 0;
}