Skip to content

Instantly share code, notes, and snippets.

@fr-xiaoli
Created November 17, 2018 01:42
Show Gist options
  • Select an option

  • Save fr-xiaoli/19596827e58d3a6349f2fcd1d9357997 to your computer and use it in GitHub Desktop.

Select an option

Save fr-xiaoli/19596827e58d3a6349f2fcd1d9357997 to your computer and use it in GitHub Desktop.
A Tour of Go - Basics - Exercise: Loops and Functions
package main
import (
"fmt"
)
func Sqrt(x float64) (z float64) {
z = x
for i := 0; i < 10; i++ {
z -= (z*z - x) / (2*z)
fmt.Printf("%d: %v\n", i, z)
}
return
}
func main() {
fmt.Println(Sqrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment