Wednesday 14 February 2024

Class 11 CS Practical - 46

 

46 - Write a program in Python to input the value of x and n and print the sum of the following series:

x + x2/2! + x3/3! + x4/4! + -------- xn /n!

import math as m

x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(1,n+1):

    sum=sum+pow(x,i)/m.factorial(i)

  print("Sum of the series=",sum)



Output:

Enter the value of x: 2

Enter the value of n: 3

Sum of the series= 5.333333333333333

 

Enter the value of x: 2

Enter the value of n: 4

Sum of the series= 6.0






No comments:

Post a Comment