go-tour/sqrt.go

18 lines
196 B
Go
Raw Normal View History

2021-04-30 10:42:29 +00:00
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));
}