C语言使用递归法计算n的阶乘
#include <stdio.h>
long Fact(int n);
int main(){
int n;
long ret;
printf("Input n:");
scanf("%d",&n);
ret =Fact(n);
if(ret==-1)
printf("n<0, data error!
");
else
printf("%d! = %ld
",n,ret);
return 0;
}
long Fact(int n){
if(n<0)
return -1;
else if (n==0||n==1)
return 1;
else
return (n*Fact(n-1));
}