参数:要求平方根的数,迭代次数
var sqrt = function (a,accur){ var pre = 1; for(var i = 0;i<accur;i++){ var cur = 1/2 * (pre + a/pre); pre = cur; } return cur; } console.log(sqrt(2,10000));
算法练习之牛顿法求平方根,布布扣,bubuko.com
算法练习之牛顿法求平方根
原文:http://blog.csdn.net/lan_liang/article/details/37365667