A clever way to calculate the square root using C languageAlgorithm From: http://zhidao.baidu.com/question/186427911.html
# include
void main () {int W, I; double ss; Double X, Y; printf ("Enter the number! \ N "); scanf (" % lf ", & Y);/* input floating point data y, that is, the equation we require the square root */x = y; /* assign y to X to save the value of Y first */SS = 1.0; For (W = 0; x> = 1; W ++) {x = X/10;}/* compress X to a decimal point, for example, 100.45 is changed to 0.10045 */W = W-1;/* and W is the X-digit minus one, for example, if you change 100.45 to 0.10045, then W = 2; */for (I = 1; I <= W; I ++) {Ss = SS * 10 ;} /* in the preceding example, the SS is changed to 100. So far, the previous work is to find the highest bit of this number. */X = 0; while (SS> 1.0/10e6) {for (; x * x
Y) {x = x-ss; SS = SS/10;} If (x * x = y) break;}/* the function of the preceding loop statement is as follows, take the preceding example: Set the square root to 0. * // * if its square is equal to the input value, it will jump out of the loop; otherwise, it will add 100. If it is greater than the input value, just cancel the action (x = x-ss;) and add 10 to it. If it is large, cancel it. If it is small, add, such a step-by-step loop */printf ("% lf \ n", x); getch () ;}