求1!+2!+3!+4!...+20!
时间: 2023-11-17 14:07:01 浏览: 81
1!+2!+3!+4!...+20!的求和问题可以通过循环和阶乘的计算来解决。具体步骤如下:
```python
# 计算1!到20!的阶乘
factorial = [1]
for i in range(1, 21):
factorial.append(factorial[-1] * i)
# 计算阶乘的和
sum = 0
for i in range(1, 21):
sum += factorial[i]
print(sum)
```
运行结果为2561327494111820313。
相关问题
求1!+2!+3!+4!+...+20!
以下是Python代码实现1!+2!+3!+4!+...+20!的求和过程:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
sum = 0
for i in range(1, 21):
sum += factorial(i)
print(sum)
```
输出结果为:2561327494111820313
求1!+2!+3!+4!+...+20!
以下是Python代码实现:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
sum = 0
for i in range(1, 21):
sum += factorial(i)
print(sum)
```
输出结果为:2561327494111820313
阅读全文