Pages

Saturday 5 July 2014

C – round() function

  • round( ) function in C returns the nearest integer value of the float/double/long double argument passed to this function.
  • If decimal value is from ”.1 to .5″, it returns integer value less than the argument. If decimal value is from “.6 to .9″, it returns the integer value greater than the argument.
  • ”math.h” header file supports round( ) function in C language. Syntax for round( ) function in C is given below.
double round (double a);
float roundf (float a);
long double roundl (long double a);

Example program for round() function in C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("round of  %f is  %f\n", i, round(i));
       printf("round of  %f is  %f\n", j, round(j));
       return 0;
}

Output:


round of 5.400000 is 5.000000
round of 5.600000 is 6.000000

0 comments:

Post a Comment