Why the output is not as expected?
#include <stdio.h>
void main(){
float a,b,c;
b=0.7;
if( b<0.7 )
printf(" It should NOT be here");
else
printf("It Should be here");
}
Why the output is not as expected?
#include <stdio.h>
void main(){
float a,b,c;
b=0.7;
if( b<0.7 )
printf(" It should NOT be here");
else
printf("It Should be here");
}
Floating point numbers
0.7
is such value. On my platform is0.699999988
. Reason: we write numbers as decimal, but internal are realised as binary. Many longer materials exist https://en.wikipedia.org/wiki/Floating-point_arithmetic#Representable_numbers.2C_conversion_and_roundingSo behaviour You are surprised