/* This program can find square root of any number that >=0 and will stop when you enter a value that < 0 */ /* This version is trying to show you that we can write our function/procedure to solve the problem, though the mysqrt() is actually calling the system standard function. We will rewrite the mysqrt() in next version. *****************************/ void hello(void); /*и穦ノ⊿把计ㄧ计hello() */ double mysqrt(double); /*穦ノmysqrt()ㄧ计,把计琌double计 */ #include /* sqrt()琌math.hず */ 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 y) { double myans; myans = -1.0; if(y < 0) printf(" can not process negative number"); else myans = sqrt(y); return myans; } /*mysqrt*/