Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

#include int main() { float f1 = 14.375; float f2 = 14.385; if(f1 == 14.375) printf("YES\n"); else printf("NO\n"); if(f2 == 14.385) printf("YES\n"); else printf("NO\n"); return 0; }

OpenStudy (anonymous):

what should be the o/p of this code and why? thnks in advance.

OpenStudy (anonymous):

Hi, try to use the debugger to see the actual values in memory see the Attach file (an image from my debugger VC++) You can see that the actual value for f2 is: 14.3850002

OpenStudy (anonymous):

try to use: f to compare with the exact precision ok see this code: #include<stdio.h> #include<float.h> using namespace std; int main() { float f1 = 14.375; float f2 = 14.385; if(f1 == 14.375f) printf("YES\n"); else printf("NO\n"); if(f2 == 14.385f) printf("YES\n"); else printf("NO\n"); return 0; }

OpenStudy (anonymous):

YES YES

OpenStudy (anonymous):

Yes Yes

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!