Tomorrow I will ask my teacher how this is supposedly derivable from Newton's method. ^_^
Code: Select all
' Square Roots!
' by Kristopher Windsor
Function squareroot (Byref number As Double) As Double
'BTW, just use SQR() instead! :-P
Static As Double r1, r2
r1 = 1
Do
r2 = r1
r1 = (r1 + number / r1) * .5
Loop Until Abs(r1 - r2) < 1E-14
Return r1
End Function
Sub showroot (Byref number As Double)
Print "The square root of " & Right("0" & number, 2) & " is " & squareroot(number)
End Sub
For a As Double = 1 To 16
showroot a
Next a
Sleep