设计操作题 未完成 设计操作题I 1 完成0/2题|共50分 1.(25分) 问题描述:编写一个程序:求N的阶乘N! (要求写一 一个子函数,主函数调用子函数实现此题)
3条回答 默认 最新
- CSDN专家-Time 2021-05-19 11:28关注
求n的阶乘很简单
#include <stdio.h> int factorial(int x); int main(int argc, char const *argv[]) { int s; printf("Enter a positive integer:\n"); scanf("%d",&s); factorial(s); printf("%d! is %d\n",s,factorial(s)); return 0; } int factorial(int x) { if (x == 0 ) { return 1; } else return x*factorial(x-1); }
。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报