∑n!(即求1!+2!+3!+...++20!)
时间: 2024-01-02 09:21:35 浏览: 84
以下是Python代码,用于计算1!+2!+3!+...+20!的和:
```python
import math
sum = 0
for i in range(1, 21):
sum += math.factorial(i)
print(sum) # 输出:2561327494111820313
```
相关问题
求∑n!(即求1!+2!+3!+4!+...+20!)的程序
以下是C语言的程序,用于计算1!+2!+3!+...+20!的和:
```c
#include <stdio.h>
int main() {
int i, j, n = 20;
long long fact = 1, sum = 0;
for (i = 1; i <= n; i++) {
fact = 1;
for (j = 1; j <= i; j++) {
fact *= j;
}
sum += fact;
}
printf("1!+2!+3!+...+20! = %lld", sum);
return 0;
}
```
求∑n!(即求1!+2!+3!+4!+...+20!)的c语言
以下是求∑n!的C语言代码:
```c
#include <stdio.h>
int main() {
int n = 20; // 求1!+2!+3!+...+20!
int i, j, ret, sum = 0;
for (i = 1; i <= n; i++) {
ret = 1;
for (j = 1; j <= i; j++) {
ret *= j;
}
sum += ret;
}
printf("%d", sum);
return 0;
}
```
阅读全文