Created
May 6, 2013 01:11
-
-
Save eckorog2005/5522817 to your computer and use it in GitHub Desktop.
sample exerise
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 := float64(1); | |
| old := float64(3); | |
| delta := float64(.00000001); | |
| for math.Abs(old - z) > delta { | |
| old = z; | |
| z = z - ((z*z - x)/(2*z)); | |
| } | |
| return z; | |
| } | |
| func main() { | |
| fmt.Println(Sqrt(1)) | |
| fmt.Println(Sqrt(2)) | |
| fmt.Println(Sqrt(3)) | |
| fmt.Println(Sqrt(4)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment