prajwalps97 said:
'void main' will make your favorite radio station switch to JackFM in mid
drive-time. Use 'int main'.
{
float a=1.9;
if(a<1.9)
cout<<"c";
else
cout<<"c++";
getch();
}
o/p is
c. how is this..
How is because 1.9 is not precise. A floating-point number is always (deep
breath) a binary representation of a mantissa and an exponent, using a fixed
number of bits for each. There are never enough bits for most fractional
numbers; even 0.1 is frequently very imprecise. Figure out for yourself what
fractional power of 2 is nearest to 0.1 in 64 bits.
Hence never expect two floats to exactly compare. If your app really really
needs a precise 1.9, then multiply your basic unit by 10 and compare 19 as
integers.