牛顿迭代(开方,板子)

就是正常的牛顿迭代求开方,牛顿迭代日后更新

开方:

#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
double sqr(double x)
{
    double k=x;
    while(k*k-x>eps)
        k=0.5*(k+x/k);
    return k;
}

int main()
{
    double x;
    while(cin>>x)
        printf("%.9f
",sqr(x));
    return 0;
}
原文地址:https://www.cnblogs.com/lalalatianlalu/p/8543503.html