void hello(void); /*и祇粆и穦ノ⊿把计ㄧ计hello() */ double mysqrt(double); /*穦ノmysqrt()ㄧ计,把计琌double计 */ int main() /* 祘Α秨﹍舘 */ { float x; hello(); /* give the user some message */ printf("X=? "); scanf("%f", &x); while(x >=0 ) { printf(" SQRT(%f)=%7.3f\n", x, mysqrt(x) ); printf("X=? "); scanf("%f", &x); } /* while */ return 0; } /**************祘Αゎ***********/ void hello() { printf("This program will ask you to input a value, say X."); printf("Then it will find the square root of X."); printf("The above process will continue ..."); printf("Negative value will cease the program."); } /* hello() */ double mysqrt(double x) { double myans; myans = -1; if(x < 0) printf(" can not process negative number\n"); else { myans = 0; /* we guess the root is zero */ while(myans*myans < x) myans++; /* 瞦0, 1, 2,...び */ if(myans*myans>x){ myans =myans-1; /*び, е搭奔 ; 糶Θmyans--*/ while(myans*myans < x) myans = myans+0.1; }; if(myans*myans>x){ myans-=0.1; /* this means : myans = myans -0.1 */ while(myans*myans < x) myans += 0.01; } if(myans*myans>x){ myans -= 0.01; while(myans*myans < x) myans += 0.001; } /* I think the precison is good enought now */ } /*else*/ return myans; /** return myans value as our answer */ } /* end of mysqrt*/ /************************************************************************ 爹: 硂祘Αいㄧ计mysqrt()┮―キよ璝獶碞穦び, 硂獶程暗猭! 莱赣т程钡氮, ㄒ, ―2キよ, 程莱σ納 1.415*1.415 籔 1.414*1.414 耕钡2, ゑ耕瞶! ************************************************************************/