float squareRoot(float value, float error){
float estimate;
float quotient;
estimate = 1;
float difference = abs(value - estimate * estimate);
while (difference > error){
quotient = value/estimate;
estimate = (estimate + quotient)/2;
difference = abs(value - estimate * estimate);
}
return difference;
}
我的函数无法编译,因为它在主函数中一直说“x 未声明”(无法修改),我做错了什么?
int main(){
printf("\nsquare root test 1: enter a number\n");
scanf("%f",&x);
printf("root(%.2f) = %.4f\n", x, squareRoot(x, .001));
getchar();
return 0;
}