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;
}

posted @ 2021-01-20 21:41  吃鲨鱼的人  阅读(119)  评论(0)    收藏  举报