+ 2
c programming question
main() { float a=0.7; if(a<0.7) printf("Stoned"); else printf("Avenged"); } output- Stoned please explain the output .
3 Antworten
+ 20
Because there's no exact representation of decimal numbers like 0.1, 0.2, 0.3 etc as the binary number inside the computer.
you can compare two float and double precision number with the same value and get an unexpected result just because the precision of the approximated binary number
float f = 10.1f;
double d = 10.1;
if ( f == d)
// yes
else
// no
And guess what, you get no.
10.9999999999 or 10.1000000001
Vs.
10.9999999999999999998 or
10.1000000000000000001
Notice: Even though floating point comparison isn't a good practice you can use it if you really know what you are gonna do.
https://code.sololearn.com/c2y59NL16jZ4
+ 5
just did it already..
https://www.sololearn.com/Discuss/644113/?ref=app