用c语言求s=1!+2!+...+n!
时间: 2023-12-01 17:43:06 浏览: 74
(完整版)c语言程序设计编程题库.doc
以下是用C语言求s=1!+2!+...+n!的代码实现:
```c
#include <stdio.h>
int main(void) {
int n = 0;
int i = 0;
int m = 1;
int sum=0;
printf("请输入n的值:"); scanf("%d", &n);
for (i=1; i<=n; ++i) {
m = m * i;
sum = sum +m;
}
printf ("sum = %d\n", sum);
return 0;
}
```
阅读全文