c语言求1!+2!+3! +4! +5! +6! +7! +8! +9! +10! 的值
时间: 2023-12-01 19:43:13 浏览: 134
以下是C语言求1!+2!+3! +4! +5! +6! +7! +8! +9! +10! 的值的代码:
```c
#include <stdio.h>
int main() {
int i, j, sum = 0, factorial = 1;
for (i = 1; i <= 10; i++) {
factorial = 1;
for (j = 1; j <= i; j++) {
factorial *= j;
}
sum += factorial;
}
printf("1!+2!+3!+...+10! = %d", sum); // 输出:1!+2!+3!+...+10! = 4037913
return 0;
}
```
相关问题
用C语言求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值
以下是使用C语言求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值的代码示例:
```c
#include <stdio.h>
int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += factorial(i);
}
printf("The sum of factorials from 1 to 10 is: %d\n", sum);
return 0;
}
```
运行结果:
```
The sum of factorials from 1 to 10 is: 4037913
```
c语言求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值。
根据引用[1]中的规律,可以得到1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值为:
```c
#include <stdio.h>
int main() {
int i, sum = 0, factorial = 1;
for (i = 1; i <= 10; i++) {
factorial *= i;
sum += factorial;
}
printf("%d", sum); // 输出:4037913
return 0;
}
```
阅读全文