其他分享
首页 > 其他分享> > 浮点数比较

浮点数比较

作者:互联网


功能:循环一直提醒用户继续输入,除非用户输入的值与正确值之间相差0.0001;
伪代码:用到fabs()引用math.h  const 定义一个值  交互
#include<stdio.h>
#include<math.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");
return 0;
}

 

标签:const,fabs,浮点数,float,response,printf,0.0001,比较
来源: https://blog.csdn.net/AKG420/article/details/88065683