Created
September 22, 2019 11:53
-
-
Save twr14152/9732600d19ad6c49b062d018f6732f70 to your computer and use it in GitHub Desktop.
Tour_go_exercises
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 := 1.0 | |
for i := 0; i < 10; i++ { | |
z -= (z * z-x) / (2 * z) | |
} | |
return z | |
} | |
func main() { | |
z := float64(16) | |
// check the math | |
fmt.Println(Sqrt(z), Sqrt(z) == math.Sqrt(z)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment