What are the floor() and ceil() functions in C++?

The floor() and ceil() methods are found in the cmath header file.

svg viewer

floor()

The floor() method returns the largest possible integer less than or equal to the number passed as an argument.

Code

#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << "Floor of -1.5 is " << floor(-1.5) << endl;
cout << "Floor of 5.9 is " << floor(5.9) << endl;
return 0;
}

ceil()

The ceil() function returns the smallest possible integer greater than or equal to the number passed as an argument.

Code

#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << "Ceiling of -3.3 is " << ceil(-3.3) << endl;
cout << "Ceiling of 8.1 is " << ceil(8.1) << endl;
return 0;
}
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved