Skip to content

Commit a345d26

Browse files
authored
added sum of series of sine and cosine program
1 parent b504dc6 commit a345d26

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import math
2+
def cosine(x,n):
3+
cosx = 1
4+
sign = -1
5+
for i in range(2, n, 2):
6+
pi=22/7
7+
y=x*(pi/180)
8+
cosx = cosx + (sign*(y**i))/math.factorial(i)
9+
sign = -sign
10+
return cosx
11+
x=int(input("Enter the value of x in degrees:"))
12+
n=int(input("Enter the number of terms:"))
13+
print(round(cosine(x,n),2))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import math
2+
def sin(x,n):
3+
sine = 0
4+
for i in range(n):
5+
sign = (-1)**i
6+
pi=22/7
7+
y=x*(pi/180)
8+
sine = sine + ((y**(2.0*i+1))/math.factorial(2*i+1))*sign
9+
return sine
10+
x=int(input("Enter the value of x in degrees:"))
11+
n=int(input("Enter the number of terms:"))
12+
print(round(sin(x,n),2))

0 commit comments

Comments
 (0)