ceil value in c++ using formula

The ceil function in C++ is used to calculate the smallest integer value greater than or equal to a given floating-point number. The formula for finding the ceil value in C++ is as follows:

ceil(x)

Where x is the floating-point number for which you want to find the ceil value.

To calculate the ceil value using the formula, you can follow these steps:

  1. Include the library at the beginning of your code to use the ceil function in C++.
#include <cmath>
  1. Declare a floating-point variable and assign a value to it.
float x = 3.14;
  1. Use the ceil function to calculate the ceil value of the variable.
float ceilValue = ceil(x);

The ceil function takes a floating-point number as an argument and returns a double value representing the smallest integer greater than or equal to the input value. In the example above, the ceil function is used to calculate the ceil value of the variable x, and the result is stored in the variable ceilValue.

  1. Print the ceil value to the console.
cout << "Ceil value of " << x << " is: " << ceilValue << endl;

The output will be the ceil value of the variable x.

Here is the complete code example:

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    float x = 3.14;
    float ceilValue = ceil(x);

    cout << "Ceil value of " << x << " is: " << ceilValue << endl;

    return 0;
}

This code will output:

Ceil value of 3.14 is: 4

This is because the ceil value of 3.14 is 4, as it is the smallest integer greater than or equal to 3.14.