Skip to content

Instantly share code, notes, and snippets.

@jingzhehu
Created April 23, 2017 23:11
Show Gist options
  • Save jingzhehu/c38048c7c95f167dd2af97c6c53f859b to your computer and use it in GitHub Desktop.
Save jingzhehu/c38048c7c95f167dd2af97c6c53f859b to your computer and use it in GitHub Desktop.
A Tour of Go: Exercise Loops and Functions
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(1)
for i := 0; i < 10; i++ {
z -= (z*z - x) / (2 * z)
}
return z
}
func main() {
fmt.Println(Sqrt(2))
fmt.Println(math.Sqrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment