C ceil() library function

The function double ceil(double x); returning the smallest integral value greater than or equal to x.

Function prototype of ceil

double ceil(double x);
  • x : A floating point value to round up.

Return value of ceil

Function ceil returns the smallest integral value greater than or equal to x(as a floating-point value).

C program using ceil function

The following program shows the use of ceil function to round up value of floating point number.

#include <stdio.h>
#include <math.h>

int main ()
{
  double x, result;
  printf("Enter a number\n");
  scanf("%lf", &x);
  
  result = ceil(x);
  printf("Smallest integer >= of %lf is %lf\n", x, result);
  
  return 0;
}

Output
Enter a number
2.3
Smallest integer >= of 2.300000 is 3.000000
Enter a number
-2.3
Smallest integer >= of -2.300000 is -2.000000