KnowledgeBoat Logo
|

Informatics Practices

WAP to print the sum of the series 1 - x2/4! + x3/6! - x4/8! + x5/10! …………… xn/(2n)! — exponential series.

Python Control Flow

2 Likes

Answer

x = int(input("Enter x: "))
n = int(input("Enter n: "))

sum_series = 1  
sign = -1 

for i in range(2, n + 1):
    fact = 1
    for j in range(1, 2 * i + 1):
        fact *= j
    
    term = sign * (x ** i) / fact
    sum_series += term
    sign *= -1 

print("Sum =", sum_series)

Output

Enter x: 2
Enter n: 3
Sum = 0.8444444444444444

Answered By

2 Likes


Related Questions