Question
We want to round off x, a float, to an int value, The correct way to do is
Answer: Option A
#include<stdio.h>
int main ()
{
float x = 3.6;
int y = (int)(x + 0.5);
printf ("Result = %d\n", y );
return 0;
}
Was this answer helpful ?
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)
Example:
#include<stdio.h>
int main ()
{
float x = 3.6;
int y = (int)(x + 0.5);
printf ("Result = %d\n", y );
return 0;
}
Output:
Result = 4.
Was this answer helpful ?
More Questions on This Topic :
Question 1.
The binary equivalent of 5.375 is
....
Question 5.
By default any real number is treated as :
....
Question 9.
Binary equivalent of 5.375 is
....
Submit Solution