标签:
fabs 是计算绝对值 %lf 是代表double类型.
下面是个小例子,浮点数比较
//浮点数比较 #include <stdio.h> #include <math.h> int main (void){ const double answer = 3.1415926; double response; printf("what is value of pi?\n"); scanf("%lf",&response); while (fabs(response - answer) > 0.0001) { printf("Try again \n"); scanf("%lf",&response); } printf("Close enough!\n"); return 0; }
标签:
原文地址:http://www.cnblogs.com/TheYouth/p/5064965.html