编程计算S=1!+2!+3!+4!+…+10!的值。用c语言表达
时间: 2023-10-08 13:12:04 浏览: 52
#include<stdio.h>
int main()
{
int i,j,fact,sum=0;
for(i=1;i<=10;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+fact;
}
printf("S= %d",sum);
return 0;
}
相关问题
编程计算S=1!+2!+3!+4!+…+10!的值。c语言
以下是C语言编写计算S=1!+2!+3!+4!+…+10!的程序:
```c
#include <stdio.h>
int main() {
int sum = 0, n = 10, a = 1, i, j;
for (i = 1; i <= n; i++) {
a = 1;
for (j = 1; j <= i; j++) {
a = a * j;
}
sum = sum + a;
}
printf("S的值为:%d\n", sum);
return 0;
}
```
编程计算S=1!+2!+3!+4!+…+10!的值。c语言编译
以下是两种C语言编译计算S=1!+2!+3!+4!+…+10!的值的例子:
引用:
```c
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int fun(int x) {
int Sn = 0;
int S;
for (int i = 1; i <= x; ++i) {
S = 1;
for (int j = 1; j <= i; ++j) {
S *= j;
}
Sn += S;
}
return Sn;
}
void main() {
int n;
printf("您需要1到多少的阶乘之和,请输入(此值请小于26)\n");
scanf("%d", &n);
printf("数字1到数字%d各阶乘之和为%d\n", n, fun(n));
system("pause");
}
```
引用:
```c
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int fun(int x) {
int Sn = 0;
int S = 1;
for (int i = 1; i <= x; ++i) {
S = i*S;
Sn += S;
}
return Sn;
}
void main() {
int n;
printf("您需要1到多少的阶乘之和,请输入(此值请小于26)\n");
scanf("%d", &n);
printf("数字1到数字%d各阶乘之和为%d\n", n, fun(n));
system("pause");
}
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)