Ceil and Floor functions in C++ Last Updated : 16 May, 2025 Suggest changes Share 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); K kartik Article Tags : C++ CPP-Library cpp-math Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like