#include <stdio.h>int jc(int n){ int result; if(n < 0){ printf("输入错误\n"); return 0; }else if(0 == n || 1 == n){ result 1; }else { result = jc(n-1)*n; } return result;}int main (){ int n = 5; printf("阶乘结果: %d\n",n,jc(n)); return 0;}
1 回答
已采纳
qq_半夏流年_0
TA贡献1条经验 获得超1个赞
#include <stdio.h>
int jc(int n)
{
int result;
if(n < 0)
{
printf("输入错误\n");
return 0;
}
else if(0 == n || 1 == n)
{
return 1;
}
else
{
result = jc(n-1)*n;
}
return result;
}
int main (){
int n = 5;
printf("阶乘结果: %d\n",jc(n));
return 0;
}
- 1 回答
- 0 关注
- 949 浏览
添加回答
举报
0/150
提交
取消