Odpowiedź:
def pierwiastek(x,eps):
a = 0
b = x
while abs(a-b) > eps:
c = (a + b) / 2
if c * c > x:
b = c
else:
a = c
return c;
print(pierwiastek(2,0.1))
print(pierwiastek(2,0.01))
print(pierwiastek(2,0.00001))
wyniki wywołań:
1.4375
1.4140625
1.4142074584960938
Wyjaśnienie:
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Odpowiedź:
def pierwiastek(x,eps):
a = 0
b = x
while abs(a-b) > eps:
c = (a + b) / 2
if c * c > x:
b = c
else:
a = c
return c;
print(pierwiastek(2,0.1))
print(pierwiastek(2,0.01))
print(pierwiastek(2,0.00001))
wyniki wywołań:
1.4375
1.4140625
1.4142074584960938
Wyjaśnienie: