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.
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.