+ 2

#include <stdio.h> void main() { float x = 0.1; if (x == 0.1) printf("Sanfoundry"); else printf("Advanced C Classes"); }

The o/p is "Advanced c classes " How ??

16th May 2020, 12:56 AM
𝒱𝑒𝓃𝑜𝓂𝑜𝓊𝓈
𝒱𝑒𝓃𝑜𝓂𝑜𝓊𝓈 - avatar
3 Respuestas
+ 5
𝔸𝕒𝕗𝕥𝕒𝕓 𝕂𝕙𝕒𝕟 What ✳AsterisK✳ said is right and if you desire to get the output as "Sanfoundry", please make sure the condition inside if is "x==0.1f" #include <stdio.h> int main() { float x = 0.1; if (x == 0.1f) printf("Sanfoundry"); else printf("Advanced C Classes"); return 0; }
16th May 2020, 1:08 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 3
x is float while just writing 0.1 is a double, hence the reason precision make em different
16th May 2020, 1:05 AM
✳AsterisK✳
✳AsterisK✳ - avatar
0
I got it. Thanks both of you.🙂
16th May 2020, 1:10 AM
𝒱𝑒𝓃𝑜𝓂𝑜𝓊𝓈
𝒱𝑒𝓃𝑜𝓂𝑜𝓊𝓈 - avatar