go-tour/sqrt.go

18 lines
196 B
Go

package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
z := 1.0;
for count := 0; count < 10; count++ {
z -= (z*z - x) / (2*z);
}
return z;
}
func main() {
fmt.Println(Sqrt(2));
}