1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
# calculate the square root geometrically (according to Heron)
# Carsten Berndt, 2007
clg
cls
fastgraphics
zuWurzeln=56224
zuZeichnen=zuWurzeln
zweiteZahl=1
delta=0.000001
print "sqrt("; : print zuWurzeln; : print ") =" ;
MainLoop:
clg
rect 0, 0, zuZeichnen, zweiteZahl
zuZeichnen = (zuZeichnen+zweiteZahl)/2
zweiteZahl = zuWurzeln/zuZeichnen
if zuZeichnen-zweiteZahl<delta then print zweiteZahl : goto Ende
refresh
pause 1
goto MainLoop
Ende:
print "Check result:";
print zweiteZahl; : print " * "; : print zweiteZahl; : print " = ";
print zweiteZahl*zweiteZahl
|