#include<iostream>
using namespace std;
double sqrt_root(double,double);
double abs_value(double);
int main()
{
double x,e;
scanf("%lf %lf",&x,&e);
if(x<=0||e<=0)
{
printf("error\n");
return 0;
}
printf("%lf square root is: %lf\n",x,sqrt_root(x,e));
return 0;
}
double abs_value(double y)
{
if(y<0)
y=-y;
return y;
}
double sqrt_root(double x,double e)
{
double x0=1;
while(abs_value(x0*x0-x)>=e)
x0=(x0+x/x0)/2;
return x0;
}
对牛顿迭代法的证明,自己不是很清楚,仅知道如何套用。