Created
January 22, 2017 07:03
-
-
Save ta1kt0me/12e5cc93ba4d367f51a8349a93ab82bd to your computer and use it in GitHub Desktop.
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" | |
| "math" | |
| ) | |
| func Sqrt(x float64) float64 { | |
| z := 9.0 | |
| for i := 0; i < 10; i++ { | |
| z = z - ((z*z - x) / (2 * z)) | |
| } | |
| return z | |
| } | |
| func main() { | |
| fmt.Println(Sqrt(3)) | |
| fmt.Println(math.Sqrt(3)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment