c - Why does this code print greater? -
this question has answer here:
- floating point comparison [duplicate] 5 answers
1)#include<stdio.h> int main() { float x=0.5; if(x>0.5) printf("\ngreater"); else printf("\nlesser "); return 0; }
output->lesser
2)#include<stdio.h> int main() { float x=0.1; if(x>0.1) printf("\ngreater "); else printf("\nlesser "); return 0; }
output->greater why in first case output "lesser" while in second 1 output "greater"? difference?
edit: understood 0.1 not equal, why 0.5 showing equal?
i sure it's because comparing float , double.
there's answer why greater answered here : 0.1 float greater double
Comments
Post a Comment