Created
May 5, 2021 11:04
-
-
Save ppsdatta/96667ee978cb299f111b0155489ea526 to your computer and use it in GitHub Desktop.
Newton's square root method in Small Basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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