# Chapter 2 - Programming and Software - Problems - Page 48: 2.7b

#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; }

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.