The ceil() function in C++ returns the smallest possible integer value which is greater than or equal to the given argument.
ceil() prototype [As of C++ 11 standard]
double ceil(double x); float ceil(float x); long double ceil(long double x); double ceil(T x); // For integral type
The ceil() function in C++ returns the smallest possible integer value which is greater than or equal to the given argument. This function is defined in <cmath> header file.
ceil() Parameters
The ceil() function takes a single argument whose ceiling value is computed.
ceil() Return value
The ceil() function returns the smallest possible integer value which is greater than or equal to the given argument.
Example 1: ceil() function for double, float and long double types
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 10.25, result;
result = ceil(x);
cout << "Ceil of " << x << " = " << result << endl;
return 0;
}
When you run the program, the output will be:
Ceil of 10.25 = 11
Example 2: ceil() function for integral types
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x = 15;
double result;
result = ceil(x);
cout << "Ceil of " << x<< " = " << result << endl;
return 0;
}
When you run the program, the output will be:
Ceil of 15 = 15
For integral types, you will always get the same result, so this function is not used with integral types in practice.