Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anurag_1812

  • 3 years ago

#include<stdio.h> 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; }

  • This Question is Open
  1. anurag_1812
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. hedjm
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    1 Attachment
  3. hedjm
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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; }

  4. fitsyu
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    YES YES

  5. classicalyomi
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes Yes

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy