c语言用循环打印n的阶乘
时间: 2023-05-22 13:04:57 浏览: 173
C语言求N的阶乘
下面是C语言用循环打印n的阶乘的代码:
```
#include <stdio.h>
int main() {
int n, i;
unsigned long long factorial = 1;
printf("请输入一个正整数:");
scanf("%d", &n);
if (n < 0) {
printf("抱歉,负数没有阶乘。\n");
}
else {
for (i = 1; i <= n; ++i) {
factorial *= i;
}
printf("%d 的阶乘为 %llu。\n", n, factorial);
}
return 0;
}
```
阅读全文