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 to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved