Open In App
Related Articles

Python program to find the sum of sine series

Improve Article
Improve
Save Article
Save
Like Article
Like

Prerequisite: math

Given n and x, where n is the number of terms in the series and x is the value of the angle in degree. The Task here is, write a program to calculate the sum of sine series of x.

Formula Used:

sinx=x-(x3/3!)+(x5/5!)-(x7/7!)+…

Example:

Input: n = 10
        x = 30
Output: sum of sine series is 0.5 

Input: n = 10
        x = 60
Output: sum of sine series is 0.87

Below is the program to calculate the sum of sine series:

Python3




# Import Module
import math
 
# Create sine function
def sin( x, n):
    sine = 0
    for i in range(n):
        sign = (-1)**i
        pi = 22/7
        y = x*(pi/180)
        sine += ((y**(2.0*i+1))/math.factorial(2*i+1))*sign
    return sine
 
# driver nodes
# Enter value in degree in x
x = 10
 
# Enter number of terms
n = 90
 
# call sine function
print(round(sin(x,n),2))


Output: 

0.17

Time complexity: O(n) for given input n
 Auxiliary Space: O(1) 

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated : 31 Jul, 2022
Like Article
Save Article
Similar Reads
Related Tutorials