The floor()
and ceil()
methods are found in the cmath
header file.
The floor()
method returns the largest possible integer less than or equal to the number passed as an argument.
#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;}
The ceil()
function returns the smallest possible integer greater than or equal to the number passed as an argument.
#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;}
Free Resources