Python implementation of the approach
#coth(x)=(e^x+e^-x)/(e^x-e^-x)
Recursive Function
global variables p and f
p = 1.0
f = 1.0
def e(x, n) :
global p, f
Termination condition
if (n == 0) :
return 1
Recursive call
r = e(x, n - 1)
Update the power of x
p = p * x
Factorial
f = f * n
return (r + p / f)
Driver code
x=int(input(“Enter the value coth(x):”))
n = 100
y=e(x,n)+e(-x,n)
p=1.0
f=1.0
z=e(x, n)-e(-x,n)
print (’%.5f’%(y/z))
(değer girdiğimde sonucu yanlış veriyo
Merhaba, öncelikle gönderiyi şuraya bakarak düzenleyebilir misiniz:
Kodun tamamını siz mi yazdınız, yoksa bir yerden mi aldınız? Recursion kullanmak yerine for döngüsüyle de yazabilirdiniz, o yüzden sordum.