Skip to content

Instantly share code, notes, and snippets.

@ppsdatta
Created May 5, 2021 11:04
Show Gist options
  • Save ppsdatta/96667ee978cb299f111b0155489ea526 to your computer and use it in GitHub Desktop.
Save ppsdatta/96667ee978cb299f111b0155489ea526 to your computer and use it in GitHub Desktop.
Newton's square root method in Small Basic
' Newton's square root method
TextWindow.Write("Enter a positive number: ")
n = TextWindow.ReadNumber()
guess = 1.0
Calculate:
diff = Math.Abs(n - (guess * guess))
If diff <= 0.001 Then
TextWindow.WriteLine(guess)
Else
guess = ((n / guess) + guess) * 0.5
Goto Calculate
EndIf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment