用c语言编写求1+2!+3!+...+20!的和
时间: 2023-11-24 18:08:40 浏览: 72
python 求1+2!+3!+...+20!的和 (示例)
5星 · 资源好评率100%
以下是用C语言编写求1+2!+3!+...+20!的和的代码:
```c
#include <stdio.h>
int main() {
int i, j;
long long sum = 0, factorial = 1;
for (i = 1; i <= 20; i++) {
factorial = 1;
for (j = 1; j <= i; j++) {
factorial *= j;
}
sum += factorial;
}
printf("1+2!+3!+...+20! = %lld\n", sum);
return 0;
}
```
运行结果为:
```
1+2!+3!+...+20! = 2561327494111820313
```
阅读全文