Latest web development tutorials

C library functions - ceil ()

C standard library - <math.h> C standard library - <math.h>

description

C library functionsdouble ceil (double x) Returns the smallest integer greater than or equal to thevalue ofx.

statement

The following is a statement ceil () function.

double ceil(double x)

parameter

  • x - floating-point value.

return value

This function returns the smallest integer not less than x value.

Examples

The following example demonstrates the ceil () function is used.

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

int main ()
{
   float val1, val2, val3, val4;

   val1 = 1.6;
   val2 = 1.2;
   val3 = 2.8;
   val4 = 2.3;

   printf ("value1 = %.1lf\n", ceil(val1));
   printf ("value2 = %.1lf\n", ceil(val2));
   printf ("value3 = %.1lf\n", ceil(val3));
   printf ("value4 = %.1lf\n", ceil(val4));
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

value1 = 2.0
value2 = 2.0
value3 = 3.0
value4 = 3.0

C standard library - <math.h> C standard library - <math.h>