Math Ceil Function

C++ Math ceil

It rounds the value to the nearest integer which is not less than the given value.

For example :

Example

ceil(8.1)=9.0;
ceil(-8.8)=-8.0;

Syntax

Suppose a number is 'x'. Syntax would be:

Example

double ceil(double x);

Parameter

x : It is the value that rounds to the nearest integer.

Return value

It returns the smallest integer value not less than x.

Example 1

Let's see a simple example by considering the positive value of x.

Example

#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:

Output

Initial value of x is :9.2
final value of x is :10

Example 2

Let's see a simple example by considering the negative value of x.

Example

#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:

Output

Initial value of x is :-2.2
final value of x is :-2

Input Required

This code uses input(). Please provide values below: