#include
#include
using namespace std;
struct stu
{
int socol[30];
};
int main()
{
double a, x0, x1;
printf("Input a:\n");
scanf("%lf", &a);//因为a是double型数据,所以要用%lf,而不是%f
if (a < 0)
printf("Error!\n");
else
{
x0 = a / 2;
x1 = (x0 + a / x0) / 2;
do
{
x0 = x1;
x1 = (x0 + a / x0) / 2;
} while (fabs(x0 - x1) >= 1e-6);
}
printf("Result:\n");
printf("sqrt(%g)=%g\n", a, x1);
}