Menu Close

Sum of Cosine Series in Python…..-FTC

Python Program to Find the Sum of Cosine Series.

Input:
First Line: Value of x in degrees
Second Line: Number of terms

Output:
Print the Sum of Cosine Series

Input:
Value of X in degrees:  65
Number of terms:  10

Output:
Sum of Cosine Series:  0.42
import math
def cosine(x,n):
    cosx = 1
    sign = -1
    for i in range(2, n, 2):
        pi=22/7
        y=x*(pi/180)
        cosx = cosx + (sign*(y**i))/math.factorial(i)
        sign = -sign
    return cosx
x=int(input("value of X in degrees:  "))
n=int(input("Number of terms:  "))
print("\nSum of the Cosine Series: ",round(cosine(x,n),2))


INPUT_1:
Value of X in degrees:  65
Number of terms:  10

OUTPUT:
Sum of the Cosine Series:  0.42


INPUT_2:
Value of X in degrees:  45
Number of terms:  10

OUTPUT:
Sum of the Cosine Series:  0.71


INPUT_3:
Value of X in degrees:  30
Number of terms:  20

OUTPUT:
Sum of the Cosine Series:  0.87


INPUT_4:
Value of X in degrees:  60
Number of terms:  20

OUTPUT:
Sum of the Cosine Series:  0.5


ILLUSTRATION

Executed using python3