Exercise: Loops and Functions (牛顿迭代法快速寻找平方根) AHUI

A Tour of Go

Exercise: Loops and Functions

https://tour.golang.org/flowcontrol/8

牛顿迭代法(简称“牛迭”)快速寻找平方根

牛迭

上面的程序求 10, 20, 30 ... 100 的平方根,运行结果如下:

运行结果

(括号里的数字是牛迭的循环次数,比如 5 表示循环了五次得出结果。)

后来发现 A Tour of Go 的 github 仓库里也有答案,参考后改写如下:

答案

参考:

https://nylira.com/a-tour-of-go-solutions/

https://gist.github.com/abesto/3476594

https://github.com/golang/tour/blob/master/solutions/loops.go

原文地址:https://www.cnblogs.com/ahui2017/p/6358565.html