#include int nextDigit ( int r , int s , int grp ) { int d = 0; /* Keep on searching for the next digit in the square root */ while ((20*s+d)*d <= 100*r+grp) ++d; /* Here d is just one bigger than the correct digit */ return(d-1); } void printSqrt ( int n ) { int s, /* Square root found so far */ r, /* Whatever remains */ d, /* next digit */ nl, /* Number of digits to the left of the decimal point */ nr = 3, /* Number of digits to the right of the decimal point */ grp[8], /* 2-digit groups */ sgn, /* Sign of n */ i; /* An index */ if (n < 0) { sgn = 1; n = -n; } else sgn = 0; if (n == 0) { nl = 1; grp[0] = 0; } else { nl = 0; while (n != 0) { grp[nl] = n % 100; /* Save next 2-digit group */ n /= 100; ++nl; } } /* Initialize */ s = 0; r = 0; /* First print the digits to the left of the decimal point */ for (i=nl-1; i>=0; --i) { d = nextDigit(r,s,grp[i]); printf("%d",d); r = (100 * r + grp[i]) - (20 * s + d) * d; s = 10 * s + d; } /* Print the decimal point */ printf("."); /* Print digits after the decimal point */ for (i=0; i