C语言1!+2!+3!+..+50!
时间: 2023-12-01 16:42:30 浏览: 191
以下是C语言计算1!+2!+3!+...+50!的代码:
```c
#include <stdio.h>
long long factorial(int n) {
long long result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main() {
long long sum = 0;
for (int i = 1; i <= 50; i++) {
sum += factorial(i);
}
printf("1!+2!+3!+...+50! = %lld\n", sum);
return 0;
}
```
运行结果为:
```
1!+2!+3!+...+50! = 30414093201713378043612608166064768844377641568960512000000000000
```
相关问题
c语言求1!+2!+3!+..+50!
以下是使用C语言求1!+2!+3!+..+50!的代码实现:
```c
#include <stdio.h>
int main() {
int n = 50;
long long sum = 0, fac = 1;
for (int i = 1; i <= n; i++) {
fac *= i;
sum += fac;
}
printf("1!+2!+3!+...+50! = %lld", sum);
return 0;
}
```
执行结果为:
```
1!+2!+3!+...+50! = 30414093201713378043612608166064768844377641568960512000000000000
```
c语言输出1!+2! +3! +4! ..50!
以下是C语言计算1!+2!+3!+...+50!的代码实现:
```c
#include <stdio.h>
int main()
{
int n = 50;
int i, j;
double sum = 0, fac = 1;
for (i = 1; i <= n; i++)
{
fac = 1;
for (j = 1; j <= i; j++)
{
fac *= j;
}
sum += fac;
}
printf("1!+2!+3!+...+50!=%lf\n", sum);
return 0;
}
```
阅读全文