#include
#include
void main()
{
double x1,x2=1.0,a;
printf("请输入a:");
scanf("%lf",&a);
do
{
x1=x2;
x2= (x1 + a/x1) / 2; //迭代的实质是循环
}while(fabs(x2-x1)>1e-1);
printf("结果为:%.2f\n",x2);
}
double sqrt(double a, double x0)
{
double x = (x0 + a/x0)/2;
if ((x - x0)>1e-1 || (x-x0)<-1e-1) return x;
return sqrt(a, x);
}