+ 2
Why this code is printing Hi?
It is printing Hi How it come? #include<stdio.h> int main() { float a = 0.7; if(a < 0.7) printf("Hi"); else printf("hellow") ; return 0; }
5 Answers
+ 3
Try to use the literal f at the end of the number. Good practice.
Example:. a=0.7f;
Also in the comparation if (a<0.7f)
If you don't use it the compiler will promote a as double when evaluate the conditional expression. Better use f literal with float numbers.
+ 3
Different programming language, same answer:
https://www.sololearn.com/Discuss/1477626/?ref=app
+ 2
Change float to double and it should work.
+ 2
Yeh that's working with double,
But why float is not working?
+ 2
Itâs because double has more precision than float.