Define a Macro to round a float value to nearest integer in C
Given a float value and we have to round the value to the nearest integer with the help of Macro in C language.
Macro Definition:
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
Example:
Input:
float val1=10.00f;
float val2=10.23f;
float val3=10.50f;
float val4=10.65f;
Output:
After round val1=10
After round val2=10
After round val3=11
After round val4=11
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer