Created
November 17, 2018 01:42
-
-
Save fr-xiaoli/19596827e58d3a6349f2fcd1d9357997 to your computer and use it in GitHub Desktop.
A Tour of Go - Basics - Exercise: Loops and Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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