Competitive Programming Questions |
In this article, we are going to write a python code to print out the value of the cosine function in the python
If you are looking for a python tutorial then it's here
def Cosine(x):
epsilon = 0.00001
multiBy = -x**2
term = 1
total = x
nxtInSeq = 1.0
while abs(term) > epsilon:
divBy = nxtInSeq*(nxtInSeq+1)
term = term * multiBy/divBy
total += term
nxtInSeq += 2
print(total)
Cosine(1)
The output of the code is:
0.540302303791887
Comments
Post a Comment