0.00001 POW (10,-5) 1e-5
/////////////////////////////////////////
# Include <stdio. h>
# Include <math. h>
Void main ()
{Double A, x1, x2;
Printf ("input a value :");
Scanf ("% lf", & );
X1 = A/2;
X2 = (X1 + A/X1)/2;
For (; FABS (x2-x1)> = 0.00001 ;)
{
X1 = x2;
X2 = (X1 + A/X1)/2;
}
Printf ("output the square root of a % F \ n", X2 );
}
//////////////////////////////////////// //////////////////////////////////////// //
# Include <stdio. h>
# Include <math. h>
Void main ()
{Double X2, X1,;
Printf ("enter a = ");
Scanf ("% lf", & );
X1 = A/2;
X2 = (X1 + A/X1)/2;
Do
{
X1 = x2;
X2 = (X1 + A/X1)/2;
} While (FABS (x2-x1)> = 1e-5 );
Printf ("the square root of A is % lf \ n", X2 );
}
//////////////////////////////////////// /////////
# Include <stdio. h>
# Include <math. h>
Void main ()
{Double A, x1, x2;
Printf ("input a value μ :");
Scanf ("% lf", & );
X1 = A/2;
X2 = (X1 + A/X1)/2;
While (FABS (x2-x1)> = POW (10,-5 ))
{
X1 = x2;
X2 = (X1 + A/X1)/2;
}
Printf ("output the square root of a % lf \ n", X2 );
}
Do While and while do are different only when the first condition is not met
The above programs should add an if (a> 0) judgment.