CBSE Class 11 Computer Science
Question 147 of 161
Flow of Control — Question 24
Back to all questions 24
Question Question 23a
Write programs to find the sum of the following series:
x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6! (Input x)
Solution
x = int(input("Enter the value of x: "))
sum = 0
m = 1
for i in range(1, 7) :
fact = 1
for j in range(1, i+1) :
fact *= j
term = x ** i / fact
sum += term * m
m = m * -1
print("Sum =", sum)Output
Enter the value of x: 2
Sum = 0.8444444444444444