Skip to content

Instantly share code, notes, and snippets.

@brianjester
Last active October 8, 2017 23:06
Show Gist options
  • Save brianjester/dcb44d280e4eb4eef73591d9718991ec to your computer and use it in GitHub Desktop.
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
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