Floating Point Issues Questions And Answers.
Exercise ::
Floating Point Issues
1. | What are the different types of real data type in C ? |
| |
| A. | float, double |
| B. | short int, double, long int |
| C. | float, double, long double |
| D. | double, long int, float |
|
|
| Answer: Option C |
|
|
| Explanation: |
|
The floating point data types are called real data types. Hence float, double, and long double are real data types. |
| See More Information |
|
|
|
Tutorial Link: |
Published by:Michael Daani
2. | What will you do to treat the constant 3.14 as a long double? |
| |
| A. | use 3.14LF |
| B. | use 3.14DL |
| C. | use 3.14L |
| D. | use 3.14LD |
|
|
| Answer: Option C |
|
|
| Explanation: |
|
Given 3.14 is a double constant.
To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L) |
| See More Information |
|
|
|
Tutorial Link: |
Published by:Michael Daani
3. | Which statement will you add in the following program to work it correctly? |
|
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
|
| A. | # include < conio.h > |
| B. | # include < math.h > |
| C. | # include< stdlib.h > |
| D. | # include< dos.h > |
|
|
| Answer: Option B |
|
|
| Explanation: |
|
math.h is a header file in the standard library of C programming language designed for basic mathematical operations.
Declaration syntax: double log(double); |
| See More Information |
|
|
|
Tutorial Link: |
Published by:Michael Daani
4. | We want to round off x, a float, to an int value, The correct way to do is? |
| |
| A. | y = (int)(x + 0.5) |
| B. | y = int(x + 0.5) |
| C. | y = (int)x + 0.5 |
| D. | y = (int)((int)x + 0.5) |
|
|
| Answer: Option A |
|
|
| Explanation: |
|
Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.
y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int) |
| See More Information |
|
|
|
Tutorial Link: |
Published by:Michael Daani
5. | The binary equivalent of 5.375 is? |
| |
| A. | 101.101110111 |
| B. | 101.011 |
| C. | 101011 |
| D. | All of above |
|
|
Published by:Michael Daani