Friday, February 1, 2019

Cosine series

  • Problem Description

    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
  • CODING ARENA
  • 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())
    n=int(input())
    print(round(cosine(x,n),2))
  • Test Case 1

    Input (stdin)
    65
    
    10
    
    
    Expected Output
    0.42
  • Test Case 2

    Input (stdin)
    75
    
    15
    
    
    Expected Output
    0.26

No comments:

Post a Comment