编写程序求1! +2! +3! ..+10!c语言
时间: 2023-11-26 11:03:48 浏览: 76
以下是C语言程序,用于计算1! +2! +3! ..+10!的值并输出:
```c
#include <stdio.h>
int main() {
int i, j;
double 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! = %lf", sum);
return 0;
}
```
相关问题
编写程序,求1!+2!+3!+...+10!,验证1!+...+10!用c语言
以下是用C语言编写程序,求1!+2!+3!+...+10!的代码:
```c
#include <stdio.h>
int main() {
int n = 10;
int sum = 0;
int sum1 = 1;
for(int i = 1; i <= n; i++) {
sum1 *= i;
sum += sum1;
}
printf("%d\n", sum);
return 0;
}
```
运行结果为:4037913
用C语言编写程序求1!+2!+....+10!
以下是用C语言编写程序求1!+2!+....+10!的代码:
```c
#include <stdio.h>
int main() {
int i, j;
double sum = 0, fac = 1;
for (i = 1; i <= 10; i++) {
fac *= i;
sum += fac;
}
printf("1!+2!+....+10!=%.0f\n", sum);
return 0;
}
```
阅读全文