124. Python Program to Compute the Cosine Series 1 - x^2/2! + x^4/4! – x^6/6! + …… x^n/n!
How does this program work?
- This program is used to find the Sum of the given Cosine series 1 - x^2/2! + x^4/4! – x^6/6! + …… x^n/n! using Python.
- The integer entered by the user is stored in variable x and n but x value in degrees.
- By using the for loop condition we can easily calculate the sum of cosine series.
Here is the code
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
s = 1
term = 1
y = 2
print("Series till the enter number: ")
print(s, end=" ")
for i in range(1,n+1):
fact = 1
for j in range(1,y+1):
fact = fact * j
term = term * (-1)
m = term * (x**y)
a = int ( m/fact )
print(a, end=" ")
s= s + a
y += 2
print("\nSum of the series: ",s)