C math ceil - Syntax
mixed ceil(mixed n);
The ceil() function in C is used to return the next highest integer value by rounding up value if necessary.
mixed ceil(mixed n);
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using ceiling math method and print the resultant in console.
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// Positive floating point value
printf("The ceiling value of 1.0 is %f \n", ceil(1.0));
printf("The ceiling value of 1.1 is %f \n", ceil(1.1));
printf("The ceiling value of 1.2 is %f \n", ceil(1.2));
printf("The ceiling value of 1.3 is %f \n", ceil(1.3));
printf("The ceiling value of 1.4 is %f \n", ceil(1.4));
printf("The ceiling value of 1.5 is %f \n", ceil(1.5));
printf("The ceiling value of 1.6 is %f \n", ceil(1.6));
printf("The ceiling value of 1.7 is %f \n", ceil(1.7));
printf("The ceiling value of 1.8 is %f \n", ceil(1.8));
printf("The ceiling value of 1.9 is %f \n", ceil(1.9));
printf("The ceiling value of 2.0 is %f \n", ceil(2.0));
return 0;
}
Round the positive floating point number (random numbers) using ceiling math method and print the resultant in console.
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// Positive floating point value
printf("The ceiling value of 1.5698 is %f \n", ceil(1.5698));
printf("The ceiling value of 1.3093 is %f \n", ceil(1.3093));
printf("The ceiling value of 1.0087 is %f \n", ceil(1.0087));
printf("The ceiling value of 1.1038 is %f \n", ceil(1.1038));
printf("The ceiling value of 1.9573 is %f \n", ceil(1.9573));
printf("The ceiling value of 1.7462 is %f \n", ceil(1.7462));
printf("The ceiling value of 1.6427 is %f \n", ceil(1.6427));
printf("The ceiling value of 1.4128 is %f \n", ceil(1.4128));
printf("The ceiling value of 1.8099 is %f \n", ceil(1.8099));
printf("The ceiling value of 1.2743 is %f \n", ceil(1.2743));
printf("The ceiling value of 2.0001 is %f \n", ceil(2.0001));
return 0;
}
Round the negative floating point number (random numbers) using ceiling math method and print the resultant in console.
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// Negative floating point value
printf("The ceiling value of -1.5698 is %f \n", ceil(-1.5698));
printf("The ceiling value of -1.3093 is %f \n", ceil(-1.3093));
printf("The ceiling value of -1.0087 is %f \n", ceil(-1.0087));
printf("The ceiling value of -1.1038 is %f \n", ceil(-1.1038));
printf("The ceiling value of -1.9573 is %f \n", ceil(-1.9573));
printf("The ceiling value of -1.7462 is %f \n", ceil(-1.7462));
printf("The ceiling value of -1.6427 is %f \n", ceil(-1.6427));
printf("The ceiling value of -1.4128 is %f \n", ceil(-1.4128));
printf("The ceiling value of -1.8099 is %f \n", ceil(-1.8099));
printf("The ceiling value of -1.2743 is %f \n", ceil(-1.2743));
printf("The ceiling value of -2.0001 is %f \n", ceil(-2.0001));
return 0;
}
Round the infinity using ceiling math method and print the resultant in console.
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// Positive ∞ infinite value
printf("The ceiling value of INFINITY is %f \n", ceil(INFINITY));
// Negative ∞ infinite value
printf("The ceiling value of INFINITY is %f \n", ceil(-INFINITY));
}