In this C++ tutorial, you will learn how to find the ceiling value of given number using ceil() function of cmath, with syntax and examples.

C ceil

C++ ceil() returns ceiling value of given number. Ceiling value is the smallest integer value greater than the given number.

Syntax

The syntax of C++ ceil() is

ceil(x)

where

Parameter Description
x A double, float, long double, or integral type value.

Returns

The return value depends on the type of value passed for parameter x. The return value of ceil(x) is

  • double if x is double or integral type.
  • float if x is float.
  • long double if x is long double.

The synopsis of ceil() function is

double ceil(double x);
float ceil(float x);
long double ceil(long double x);
double ceil(T x); // where T is integral type

ceil() is a function of cmath library. Include cmath library at the start of program, if using ceil() function.

Example

In this example, we read a double value from user into x, and find its ceiling value using ceil() function.

C++ Program

#include <iostream>
#include<cmath>
using namespace std;

int main() {
    double x;
    cout << "Enter a value : ";
    cin >> x;
    
    double result = ceil(x);
    cout << "ceil(" << x << ") : " << result << endl;
}

Output

Enter a value : 3.14
ceil(3.14) : 4
Program ended with exit code: 0
Enter a value : 4.896
ceil(4.896) : 5
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned the syntax of C++ ceil(), and how to use this function to find the ceiling value of given number, with the help of examples.