编写函数fun,计算下列多项式:s=1+x+x**2/2!+x**3/3!+•••+x**n/n!
时间: 2023-11-03 22:14:39 浏览: 163
C语言编程-编写函数fun求1!+2!+3!+ …… +n!的和,在main函数中由键盘输入n值,并输出运算结果;
5星 · 资源好评率100%
Sure, I can help you with that! Here is the function:
```python
def fun(x, n):
s = 1
fact = 1
for i in range(1, n+1):
fact *= i
s += (x ** i) / fact
return s
```
Simply pass in the value of `x` and the number of terms `n` you want to use in the approximation. The function will return the value of the sum of the series.
Hope this helps!
阅读全文