+ 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 Respostas
+ 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