Floating Point Issues

Q1: What will be the output of the program?
#include<stdio.h>
int main()
{
    float a=0.7;
    if(a < 0.7)
        printf('C\n');
    else
        printf('C++\n');
    return 0;
}

A C

B C++

C Compiler error

D Non of above

ANS:A - C

if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'
Example:

#include<stdio.h>
int main()
{
    float a=0.7;
    printf('%.10f %.10f\n',0.7, a);
    return 0;
}
Output:
0.7000000000 0.6999999881



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.