C++ Math ceil
It approximates the input to the closest integer that is greater than or equal to the specified value.
For example :
ceil(8.1)=9.0;
ceil(-8.8)=-8.0;
Syntax
Suppose a number is 'x'. Syntax would be:
double ceil(double x);
Parameter
x : It represents a value that is rounded to the closest whole number.
Return value
It gives back the minimum integer value that is greater than or equal to x.
Example 1
Let's explore a straightforward illustration by taking into account the non-negative value of x.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
float x=9.2;
std::cout << "Initial value of x is :"<<x;
cout<<'\n';
cout<<"final value of x is :"<<ceil(x);
return 0;
}
Output:
Initial value of x is :9.2
final value of x is :10
Example 2
Let's examine a basic illustration using the inverse value of x.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
float x=-2.2;
std::cout << "Initial value of x is :"<<x;
cout<<'\n';
cout<<"final value of x is :"<<ceil(x);
return 0;
}
Output:
Initial value of x is :-2.2
final value of x is :-2