write a program to input the value of x and n print the sum of the following series x+x²/2! -x³/3! +x⁴/4-------------x^n/n!
Answers
Answered by
5
Required Answer:-
Question:
- Write a program to calculate the sum of the given series.
Solution:
Here comes the program.
n=int(input("Enter limit - "))
x=int(input("Enter x - "))
s,f,c=x,2,1
for i in range(2,n+1):
s+=c*(x * * i)/f
f=f * (i+1)
c * = -1
print("Sum: ",s)
Algorithm:
- START
- Accept n and x.
- Assume sum = x, f=2 and c=1
- Create a loop that iterates n - 1 times.
- Add c*x^i/f where f is the factorial of i.
- Multiply c with -1 as consecutive terms are added and subtracted.
- Display the result.
- STOP
Refer to the attachment for output ☑.
Attachments:
Similar questions