C Programming

C Programming

Floating Point Issues has 19 Questions

What are the different types of real data type in C ?

float, double
short int, double, long int
float, double, long double
double, long int, float
What will be the output of the program?
#include<stdio.h>
int main()
{
    float a=0.7;
    if(a < 0.7)
        printf("C");
    else
        printf("C++");
    return 0;
}

C
C++
Compiler error
Non of above
What will you do to treat the constant 3.14 as a long double?

use 3.14LD
use 3.14L
use 3.14DL
use 3.14LF
What will be the output of the program?
#include<stdio.h>
int main()
{
    float *p;
    printf("%d", sizeof(p));
    return 0;
}

2 in 16bit compiler, 4 in 32bit compiler
4 in 16bit compiler, 2 in 32bit compiler
4 in 16bit compiler, 4 in 32bit compiler
2 in 16bit compiler, 2 in 32bit compiler
If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?
#include<stdio.h>
#include<math.h>
int main()
{
    float a=5.375;
    char *p;
    int i;
    p = (char*)&a;
    for(i=0; i<=3; i++)
        printf("%02x", (unsigned char)p[i]);
    return 0;
}

40 AC 00 00
04 CA 00 00
00 00 AC 40
00 00 CA 04
What will be the output of the program?
#include<stdio.h>
int main()
{
    float fval=7.29;
    printf("%d", (int)fval);
    return 0;
}

0
0.0
7.0
7
Which of the following range is a valid long double ?

3.4E-4932 to 1.1E+4932
3.4E-4932 to 3.4E+4932
1.1E-4932 to 1.1E+4932
1.7E-4932 to 1.7E+4932
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
    printf("%f", sqrt(36.0));
    return 0;
}

6.0
6
6.000000
Error: Prototype sqrt() not found.
Which statement will you add in the following program to work it correctly?
#include<stdio.h>
int main()
{
    printf("%f", log(36.0));
    return 0;
}

#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
    printf("%d, %d, %d", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
    return 0;
}

4, 4, 4
4, 8, 8
4, 8, 10
4, 8, 12
We want to round off x, a float, to an int value, The correct way to do is

y = (int)(x + 0.5)
y = int(x + 0.5)
y = (int)x + 0.5
y = (int)((int)x + 0.5)
What will be the output of the program?
#include<stdio.h>
int main()
{
    float f=43.20;
    printf("%e, ", f);
    printf("%f, ", f);
    printf("%g", f);
    return 0;
}

4.320000e+01, 43.200001, 43.2
4.3, 43.22, 43.21
4.3e, 43.20f, 43.00
Error
The binary equivalent of 5.375 is

101.101110111
101.011
101011
None of above
What will be the output of the program?
#include<stdio.h>
int main()
{
    float a=0.7;
    if(a < 0.7f)
        printf("C");
    else
        printf("C++");
    return 0;
}

C
C++
Compiler error
Non of above
A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

ABCD
DCBA
0xABCD
Depends on big endian or little endian architecture
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
    float n=1.54;
    printf("%f, %f", ceil(n), floor(n));
    return 0;
}

2.000000, 1.000000
1.500000, 1.500000
1.550000, 2.000000
1.000000, 2.000000
What will you do to treat the constant 3.14 as a float?

use float(3.14f)
use 3.14f
use f(3.14)
use (f)(3.14)
What will be the output of the program?
#include<stdio.h>
int main()
{
    float d=2.25;
    printf("%e,", d);
    printf("%f,", d);
    printf("%g,", d);
    printf("%lf", d);
    return 0;
}

2.2, 2.50, 2.50, 2.5
2.2e, 2.25f, 2.00, 2.25
2.250000e+000, 2.250000, 2.25, 2.250000
Error
Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?

rem = (5.5 % 1.3)
rem = modf(5.5, 1.3)
rem = fmod(5.5, 1.3)
Error: we can't divide