Created
December 2, 2017 18:35
-
-
Save youchen/dff154aa789fb075554f14553384ea15 to your computer and use it in GitHub Desktop.
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) float64 { | |
z := 1.0 | |
it := 0 | |
for z < x && it < 10 { | |
z -= (z*z - x) / (2 * z) | |
fmt.Println(z) | |
it += 1 | |
fmt.Println("Iteration: ", it) | |
fmt.Println() | |
} | |
return z | |
} | |
func main() { | |
fmt.Println("Sol: ", Sqrt(2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment