0

I wanna know the best explanation of the output of this code

#include<stdio.h> int main() { float a=0.9; if(a==0.9) printf("Hello"); else printf("World") ; return 0; }

28th Jul 2019, 8:16 AM
Deepraj Baidya
Deepraj Baidya - avatar
5 odpowiedzi
+ 4
It's because of float accuracy. In fact a is not 0.9 but 0.89..... (look in the code).Just declare "a" as double which has more accuracy and you'll achieve what you want. Hope it helps you 😉 https://code.sololearn.com/ch8au03xP5OK/?ref=app
28th Jul 2019, 8:29 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
That's a goodie. Thanks TheWh¡teCat :)
28th Jul 2019, 8:33 AM
Deepraj Baidya
Deepraj Baidya - avatar
+ 2
You are welcome Deepraj Baidya 👍
28th Jul 2019, 9:14 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
I know the solution, just wanted to know the explanation of the output. Anyway, thanks
28th Jul 2019, 10:48 AM
Deepraj Baidya
Deepraj Baidya - avatar