Relational operator in C while using real variables

435 views Asked by At

Why the output is not as expected?

#include <stdio.h>
void main(){
    float a,b,c;
    b=0.7;
    if( b<0.7 )
        printf(" It should NOT be here");
    else
        printf("It Should be here");
}
3

There are 3 answers

1
Jacek Cz On

Floating point numbers

So behaviour You are surprised

7
Ganeshdip On

0.7 is double value. Try 0.7f in code. It should work.

9
Nikolaos Polygenis On

Please Try the below Code, it works!!!:

Code

 #include <stdio.h>

    int  main(void)
    {

    float a,b,c,temp;
    temp=0.7;
    b=0.7;

    if( b<temp )
        printf(" It should NOT be here");
    else
        printf("It Should be here");


    }