浮点数的比较
程序员文章站
2022-03-30 16:37:12
...
//功能:循环一直提醒用户继续输入,除非用户输入的值与正确值之间相差0.0001;
//伪代码:用到fabs()引用math.h const 定义一个值 交互
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
const float answer = 3.14159;
float response;
printf("what is the value of pi?\n");
scanf("%f", &response);
while (fabs(response - answer) > 0.0001)
{
printf("try it again!\n");
scanf("%f", &response);
}
printf("close enough!\n");
system("pause");
return 0;
}
上一篇: 甜食冷饮,夏天不用出门在家就能做
下一篇: 如何用CSS进行网页布局-三列布局?