Answer
#include
# include
int main(void)
{
$\ \ \ \ $ double y,a,e,sqroot;
$\ \ \ \ $ scanf("%lf",&a);
$\ \ \ \ $ if(a>0)
$\ \ \ \ $ {
$\ \ \ \ $$\ \ \ \ $ double tol=0.000001;
$\ \ \ \ $$\ \ \ \ $ double x=a/2;
$\ \ \ \ $$\ \ \ \ $ do
$\ \ \ \ $$\ \ \ \ $ {
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $y=(x+a/x)/2;
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $e=abs((y-x)/y);
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $x=y;
$\ \ \ \ $$\ \ \ \ $ } while (e>=tol);
$\ \ \ \ $$\ \ \ \ $ sqroot=x;
$\ \ \ \ $ }
$\ \ \ \ $ else sqroot=0;
$\ \ \ \ $ printf("%g",sqroot);
$\ \ \ \ $ return 0;
}
Work Step by Step
#include
# include
int main(void)
{
$\ \ \ \ $ double y,a,e,sqroot;
$\ \ \ \ $ scanf("%lf",&a);
$\ \ \ \ $ if(a>0)
$\ \ \ \ $ {
$\ \ \ \ $$\ \ \ \ $ double tol=0.000001;
$\ \ \ \ $$\ \ \ \ $ double x=a/2;
$\ \ \ \ $$\ \ \ \ $ do
$\ \ \ \ $$\ \ \ \ $ {
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $y=(x+a/x)/2;
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $e=abs((y-x)/y);
$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $x=y;
$\ \ \ \ $$\ \ \ \ $ } while (e>=tol);
$\ \ \ \ $$\ \ \ \ $ sqroot=x;
$\ \ \ \ $ }
$\ \ \ \ $ else sqroot=0;
$\ \ \ \ $ printf("%g",sqroot);
$\ \ \ \ $ return 0;
}