fabs()函数(声明在math.h头文件中)该函数返回一个浮点值的绝对值。
#include <stdio.h>
#include <math.h>
int main(void)
{
const double ANSWER = 3.14159;
double response;
printf("What is the value of pi?\n");
scanf_s("%lf", &response);
while (fabs(response - ANSWER) > 0.0001)
{
printf("Try again!\n");
scanf_s("%lf", &response);
}
printf("Close enough!\n");
getchar(); getchar(); getchar(); getchar(); getchar(); getchar();
return 0;
}
浙公网安备 33010602011771号