Skip to content

Instantly share code, notes, and snippets.

@takatoshiono
Last active September 7, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takatoshiono/e0b2bdf798ec35f1f654d5abc8599317 to your computer and use it in GitHub Desktop.
Save takatoshiono/e0b2bdf798ec35f1f654d5abc8599317 to your computer and use it in GitHub Desktop.
A Tour of Go: Exercise: Loops and Functions, https://go-tour-jp.appspot.com/flowcontrol/8
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i < 10; i++ {
z = z - (math.Pow(z, 2)-x)/(2*z)
}
return z
}
func main() {
for i := 1.0; i < 10; i++ {
fmt.Printf("Sqrt(%f) = ", i)
fmt.Println(
math.Sqrt(i),
Sqrt(i),
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment