Skip to content

Instantly share code, notes, and snippets.

@youchen
Created December 2, 2017 18:35
Show Gist options
  • Save youchen/dff154aa789fb075554f14553384ea15 to your computer and use it in GitHub Desktop.
Save youchen/dff154aa789fb075554f14553384ea15 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
z := 1.0
it := 0
for z < x && it < 10 {
z -= (z*z - x) / (2 * z)
fmt.Println(z)
it += 1
fmt.Println("Iteration: ", it)
fmt.Println()
}
return z
}
func main() {
fmt.Println("Sol: ", Sqrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment