Last active
October 8, 2017 23:06
-
-
Save brianjester/dcb44d280e4eb4eef73591d9718991ec to your computer and use it in GitHub Desktop.
A Tour of Go - Basics - Flow Control Statements... - Exercise Loops and Functions (8/14) - Newton's Method of square root
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
package main | |
import ( | |
"fmt" | |
) | |
func Sqrt(x float64) float64 { | |
result := 1.0 | |
for count := 0 ;count < 10;count++ { | |
result = result - ((result*result - x)/(2*result)) | |
//fmt.Println(x) | |
} | |
return result | |
} | |
func main() { | |
fmt.Println(Sqrt(169)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment