Go implementation of square root function using Newton’s method
1 min readAug 4, 2017
When you begin to learn the trending Go lang you may have encounter with the exercise to implement the square root function using Newton’s method. Here is how I implemented it.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
var z float64=1
for i:=1;i<=10;i++{
z =(z-(math.Pow(z,2)-x)/(2*z))
}
return z
}
func main() {
fmt.Println(Sqrt(64))
}