import (
"fmt"
"math"
)
const Delta = 1e-10
func Sqrt(x float64) float64 {
i := 0
z := float64(1)
prev := z
for i < 10 {
z -= (z * z - x) / (2 * z)
fmt.Println(z)
if math.Abs(z - prev) < Delta {
break;
}
prev = z
i++
}
return z
}
func main() {
fmt.Println(Sqrt(2))
}
No comments:
Post a Comment