问题描述
//这是我的代码
#include<stdio.h>
#include<stdlib.h>
int main()
{
int N;
scanf("%d",&N);
int i,ct=0;//ct is to count how many given inputs of W & H fulfill the if and else if conditional statements given below.
float W,H,ratio;//W and H are width and rectangle of rectangle respectively.ratio is ratio b/w W&H.
for(i=0;i<N;i++)
{
scanf("%f%f",&W,&H);
ratio=W/H;
printf("%f\n",ratio);
if(ratio==1.7)//this statement is not getting executed for some reason
{
printf("true\n");
ct++;
}
else if(ratio>1.6)
{
if(ratio<1.7)
ct++;
}
}
printf("%d",ct);
}
注意:当我输入以下内容时
1
10 1
假定的输出是
ct=1
我的输出是
ct=0
// ratio是1.7,但是如果上面的语句没有执行,这就是ct没有更新的原因 我想知道上面的if语句出了什么问题。
解决方法
1.7可能是b1 1.700000001
如果(abs(ratio-1.7)