1!+2!+3!+4!+5!+6!+7!+8!+9!+10!c语言for循环写
时间: 2023-05-26 18:06:32 浏览: 102
#include <stdio.h>
int main() {
int i, j, factorial;
for (i = 1; i <= 10; i++) {
factorial = 1;
for (j = 1; j <= i; j++) {
factorial *= j;
}
printf("%d! = %d\n", i, factorial);
}
return 0;
}
相关问题
1+2!+3!+4!+5!+6!+7!+8!+9!+10!c语言
以下是求1到10的阶乘和的C语言代码:
```c
#include <stdio.h>
int main() {
int sum = 0, factorial = 1;
for (int i = 1; i <= 10; i++) {
factorial *= i;
sum += factorial;
}
printf("1! + 2! + 3! + ... + 10! = %d\n", sum);
return 0;
}
```
输出结果为:1! + 2! + 3! + ... + 10! = 4037913
--相关问题--:
1. 如何在C语言中计算一个数的阶乘?
2. 如何在C语言中使用for循环?
3. 如何在C语言中使用printf函数
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 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;
}
```
阅读全文