floor and ceil in cpp

The floor() function in C++ is used to find the largest integer value that is less than or equal to a given number. It rounds down the number to the nearest integer. The function takes a single argument, which is the number to be rounded down, and returns the rounded down value.

Here is an example of how to use the floor() function in C++:

#include <iostream>
#include <cmath>

int main() {
    double number = 3.8;
    double result = std::floor(number);

    std::cout << "The floor of " << number << " is " << result << std::endl;

    return 0;
}

Output:

The floor of 3.8 is 3

The ceil() function in C++ is used to find the smallest integer value that is greater than or equal to a given number. It rounds up the number to the nearest integer. The function takes a single argument, which is the number to be rounded up, and returns the rounded up value.

Here is an example of how to use the ceil() function in C++:

#include <iostream>
#include <cmath>

int main() {
    double number = 3.2;
    double result = std::ceil(number);

    std::cout << "The ceil of " << number << " is " << result << std::endl;

    return 0;
}

Output:

The ceil of 3.2 is 4