C语言实验——求阶乘(循环结构)
Time Limit: 3000MS
Memory Limit: 65536KB
Problem Description
从键盘输入任意一个大于等于0的整数n,然后计算n的阶乘,并把它输出。
提示: 0!是 1 。
Input
输入任意一个大于等于0的整数n。
Output
输出n!
Example Input
3
Example Output
6
Hint
Author
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b = 1;
int i;
scanf("%d",&a);
for(i = 0;i < a;i++){
b = b * (i + 1);
}
printf("%d",b);
return 0;
}
本文介绍了一个简单的C语言程序,用于计算用户输入的任意非负整数的阶乘。通过循环结构逐步累乘,最终输出结果。例如输入3,程序将输出6。
5万+

被折叠的 条评论
为什么被折叠?



