(2)1!+2!+3!+4!+……+n! n=20
时间: 2023-11-24 09:51:54 浏览: 75
C语言编程-编写函数fun求1!+2!+3!+ …… +n!的和,在main函数中由键盘输入n值,并输出运算结果;
5星 · 资源好评率100%
以下是Python计算1!+2!+3!+4!+……+n!的方法:
```python
def factorial_sum(n):
sum = 0
factorial = 1
for i in range(1, n+1):
factorial *= i
sum += factorial
return sum
n = 20
result = factorial_sum(n)
print(result)
```
输出结果为:2561327494111820313
阅读全文