Ceil and Floor functions in C++ Last Updated : 16 May, 2025 Comments Improve Suggest changes Like Article Like Report C++ provides floor() and ceil() functions, defined in the <cmath> header file, to find the rounded-down and rounded-up values of floating-point numbersfloor() Functionfloor() function takes floating point number as input and returns the largest integer that is smaller than or equal to the value passed as the argument.Syntax: C++ floor(num); Example: CPP #include <iostream> #include <cmath> using namespace std; int main() { // using floor function which // return floor of input value cout << "Floor of 2.3 is : " << floor(2.3) << endl; cout << "Floor of -2.3 is : " << floor(-2.3); return 0; } OutputFloor of 2.3 is : 2 Floor of -2.3 is : -3ceil() Functionceil() function in C++ returns the smallest integer that is greater than or equal to the value passed as the input argument.Syntax: C++ ceil(num); Example: C++ #include <cmath> #include <iostream> using namespace std; int main() { // using ceil function which return // floor of input value cout << " Ceil of 2.3 is : " << ceil(2.3) << endl; cout << " Ceil of -2.3 is : " << ceil(-2.3); return 0; } Output Ceil of 2.3 is : 3 Ceil of -2.3 is : -2 Difference between ceil() and floor() in C++The ceil and floor functions are important for rounding numbers. Let us see the differences between ceil() and floor() functions in tabular form:S.Noceil() Functionfloor() Function1.It is used to return the smallest integral value n that is not less than n.It is used to return the largest integral value n that is not greater than n.2.It rounds the n upwards.It rounds the n downwards.3.Its syntax is -:data_type ceil (n);Its syntax is -:data_type floor (n); Comment More infoAdvertise with us Next Article Ceil and Floor functions in C++ S Sahil Rajput Improve Article Tags : C++ Computer Science Fundamentals CPP-Library cpp-math Practice Tags : CPP Similar Reads lrint() and llrint() in C++ lrint() in C++ The lrint() function rounds the fractional value given in the argument to an integral value using the current rounding mode. This function is defined in <cmath> library. The current mode is determined by the function fesetround(). Note:This function returns the final value in lo 5 min read abs(), labs(), llabs() functions in C/C++ The std::abs(), std::labs() and std::llabs() in C++ are built-in functions that are used to find the absolute value of any number that is given as the argument. Absolute value is the value of a number without any sign. These functions are defined inside the <cmath> header file.In this article, 3 min read Inbuilt function for calculating LCM in C++ Many times while we do programming, we need to calculate the Least Common Multiple (LCM) between two numbers. We have already discussed how to find LCM in this post. In place of defining and then using a function for calculating lcm , we can simply use an inbuilt function of boost library of C++ , b 2 min read scalbn() function in C++ The scalbn() function is defined in the cmath header file. This function is used to calculate the product of given number x and FLT_RADIX raised to the power n. Syntax:- float scalbn(float x, int n); or double scalbn(double x, int n); or long double scalbn(long double x, int n); or double scalbn(int 2 min read lldiv() function in C++ STL The lldiv() is a builtin function in C++ STL which gives us the quotient and remainder of the division of two numbers. Syntax: lldiv(n, d) Parameters: The function accepts two mandatory parameters which are described below: n: It specifies the dividend. The data-type can be long long or long long in 2 min read Like