0

Why print else part not if part any one knows answer tell me

void main() { float a=1.1; if (a==1.1) printf("santosh"); else printf("find reason"); getch(); }

26th Aug 2022, 3:15 PM
AADARSH KUMAR
AADARSH KUMAR - avatar
3 Respostas
+ 3
The issue is that you are trying to compare to floats for equality. It is likely that a floating point precision error occurs: https://floating-point-gui.de/errors/comparison/
26th Aug 2022, 3:20 PM
Lisa
Lisa - avatar
+ 3
If a fractional number is written without the f suffix, then it is a double type precision, so you are trying to compare two different precision classes, which naturally gives false. Debug: float a=1.1; if (a==1.1f) printf("santosh");
26th Aug 2022, 5:27 PM
Solo
Solo - avatar
+ 2
// Try it if (a==(float)1.1)
26th Aug 2022, 3:31 PM
SoloProg
SoloProg - avatar