#include<stdio.h>
#include<math.h>
void main()
{
float a=123.43;
float b=123.65;
float c=123.43+123.65;
if(abs((a+b)-c)<1e-6)//若用if((a+b)==c)则不可以,因为浮点数是不精确的,如b=123.65,在计算机的就可能会不一样,大家可以试试;输出b看看
printf("xiangdeng");
else
printf("buxiangdeng");
}
求浮点数是否相等
最新推荐文章于 2023-08-12 21:08:16 发布