为什么我的编码输出是0
我觉得我的编码几乎是正确的,DEVC++中没有错误,请帮我找出我的编码的错误
代码
#include <stdio.h>
int factorial(int);
int main()
{
int n;
printf("Enter a number to find it's Factorial: ");
scanf("%d", &n);
if (n < 0)
{
printf("Factorial of negative number not possible\n");
}
else
{
printf("%d!=%d\n",n, factorial(n));
}
printf("The factorial is %d",factorial(n));
}
int factorial(int n)
{
if (n == 1)
{
return 0;
}
else
{
return(n * factorial(n - 1));
}
}
最佳答案
替换 如果(n==1) 返回0;
与 如果(n==1 || n==0) 返回1;
1!是 1。
关于c - 用 C 程序求阶乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42932028/