+ 2
What is the output? and why? With proper explaination.
// only logic { float a=0.7; if(a<0.7) printf("hi"); else printf("bye"); } // upvote if you liked this. thanks in advance.
7 Antworten
+ 5
ok thanx for the info i was wrong
but what do you mean by "ans"?
+ 2
if a is int then ans will be bye but here ans will be hi bez a is of type float. You can check by compiling program.
or print this line ::: printf("%.5f %.5f ", 0.7 ,0.7f); you will find difference.
+ 2
out put for:: printf("%.5f %.5f ", 0.7 ,0.7f);
0.77777 0.69999
for float it read as 0.69999 and for double 0.77777
so at (a<0.7)// it will compare (0.69<0.7 ) which is true so it will give o/p" hi".
You can check this code. I hope you guys find this information interesting.
0
bye
0
is this answer correct
0
ans is "hi" because a = 0.7 but since it is float it will be read as 0.69
0
probably "bye" because a is something like 0.70000001. comparing floats is dangerous because floats rarely are completely accurate. read more about floats and how to compare them: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/