+ 4

#include <stdio.h> int main() { float a=0.7; if(a>0.7) printf("condition true"); else printf ("condition false");}

Case 1.. if(a>0.7) it will print Condition false.. Case 2.. if(a<0.7) it will print Condition true.. how?

5th Nov 2019, 5:13 PM
Amar kumar
Amar kumar - avatar
2 Antworten
+ 4
Run this and you'll have an idea why. Float data type has precision upto 7 digits while double data has precision upto 14 digits. Float loses precision after 7 digits. So double has more precision. Since variable 'a' is of float data type while 0.7 in the if condition is of double data type. 'a' loses its precision which results in false boolean value. #include <stdio.h> int main() { float a = 0.7; if(a > 0.7) printf("condition true\n"); else printf ("condition false\n"); printf("float: %.14f\n", a); printf("double: %.14f\n", 0.7); }
5th Nov 2019, 5:35 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
thankx
5th Nov 2019, 5:40 PM
Amar kumar
Amar kumar - avatar