要求,输入一个正整数,计算平方根,计算到1-4e为止
不得使用现成的函数。
http://blog.sina.com.cn/s/blog_47180e8f01000a47.html
#include
#include
int main()
{
float a,x0,x1;
printf("enter a positive number:");
scanf("%f",&a);
x0=a/2;
x1=(x0+a/x0)/2;
do
{x0=x1;
x1=(x0+a/x0)/2;
}while(fabs(x0-x1)>=1e-4);
printf("The square root of %5.2f is %8.5f\n",a,x1);
return 0;
}