Computer Science, asked by siddharthgager30, 2 months ago

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 anindyaadhikari13
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:

  1. START
  2. Accept n and x.
  3. Assume sum = x, f=2 and c=1
  4. Create a loop that iterates n - 1 times.
  5. Add c*x^i/f where f is the factorial of i.
  6. Multiply c with -1 as consecutive terms are added and subtracted.
  7. Display the result.
  8. STOP

Refer to the attachment for output ☑.

Attachments:
Similar questions