//此函數將計算一個數的就對值
#include
float absoluteValue (float x)
{
if ( x < 0 )
x = -x;
return x;
}
//此函數計算一個數的絕對值
float squreRoot (float x)
{
const float epsilon = 0.00001;
float guess =1.0;
while ( absoluteValue (guess * guess - x) >= epsilon );
guess = ( x/guess + guess)/2;
return guess;
}
int main()
{
int number;
printf("What number you want to square?\n");
float x;
scanf("%f",&x);
printf("%f\n" , squreRoot (x) );
return 0;
}
while那一句後面的分號去掉。