Why the output is showing NO? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the output is showing NO?

main() { float a=1.1; if(a==1.1) printf("yes"); else printf("no"); }

12th Sep 2019, 8:20 AM
Nimisha Agarwal
Nimisha Agarwal - avatar
3 Answers
+ 2
Because the 1.1 in the if statement is a double, which has a more precise and accurate representation of the float used in the declaration of a. Try with if(a==1.1f) the f suffix forces the compiler to treat 1.1 as a float.
12th Sep 2019, 12:32 PM
AndreaC
AndreaC - avatar
+ 1
Thanks@ AndreaC...😊😊😊
12th Sep 2019, 1:53 PM
Nimisha Agarwal
Nimisha Agarwal - avatar
0
You're welcome.
12th Sep 2019, 2:58 PM
AndreaC
AndreaC - avatar