import math
def cosine_series_sum(x, n):
"""
Calculate the sum of the cosine series up to n terms for a given x.
:param x: The angle in radians
:param n: The number of terms in the series
:return: The sum of the cosine series
"""
cosine_sum = 0
sign = 1
for i in range(n):
term = sign * (x**(2 * i)) / math.factorial(2 * i)
cosine_sum += term
sign *= -1
return cosine_sum
x = float(input("Enter the value of x (in radians): "))
n = int(input("Enter the number of terms in the series: "))
result = cosine_series_sum(x, n)
print(f"The sum of the cosine series up to {n} terms for x = {x} is: {result}")
#source code --> clcoding.com
0 Comments:
Post a Comment