基本的函数
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; }
将来的自己,会感谢现在不放弃的自己!