Math Ceil Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Ceil Function

Math Ceil Function

BLUF: Mastering Math Ceil Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Ceil Function

C++ is renowned for its efficiency. Learn how Math Ceil Function enables low-level control and high-performance computing in the tutorial below.

C++ Math ceil

It approximates the input to the closest integer that is greater than or equal to the specified 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 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.

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 examine a basic illustration using the inverse 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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience