The ceil() function defined in the math.h header file. It helps to return the smallest or nearest integer value greater than or equal to the given argument value.
double ceil( double x ); #where x should be in double
Also, two functions ceilf() and ceill() were used with type float and long double respectively.
float ceilf(float x);
long double ceill(long double x);
The ceil() function takes a single parameter in double.
Parameter | Description | Required / Optional |
---|---|---|
double value | whose greater nearest integer needs to be found | Required |
The return value of ceil() function is a number in the integer.
Input | Return Value |
---|---|
double value | integer |
#include <stdio.h>
#include <math.h>
int main()
{
double N = 4.82;
int ouput;
ouput = ceil(N);
printf("Ceiling integer of given %.2f = %d", N, ouput);
return 0;
}
Output:
Ceiling integer of given 4.82 = 5
#include <stdio.h>
#include <math.h>
int main () {
float v1, v2, v3, v4;
v1 = 3.5;
v2 = 4.8;
v3 = 5.3;
v4 = 6.7;
printf ("value1 = %.1lf\n", ceil(v1));
printf ("value2 = %.1lf\n", ceil(v2));
printf ("value3 = %.1lf\n", ceil(v3));
printf ("value4 = %.1lf\n", ceil(v4));
return(0);
}
Output:
value1 = 4.0 value2 = 5.0 value3 = 6.0 value4 = 7.0