编程计算S=1!+2!+3!+4!+…+10!的值。c语言代码
时间: 2023-11-24 17:51:34 浏览: 94
计算 S=1!+2!+3!+...+N! C语言代码
以下是C语言代码,用for循环计算S=1!+2!+3!+4!+…+10!的值:
```c
#include <stdio.h>
int main() {
int sum = 0, factorial = 1;
for (int i = 1; i <= 10; i++) {
factorial *= i;
sum += factorial;
}
printf("S = %d\n", sum);
return 0;
}
```
阅读全文