Blog

ceil function

 

 

What is ceil function in C++ ?

 

ceil function ceil is a function that provides the next possible greater than or an equal integer number as output to a random number provided as the input in the form of a parameter. This function is generally defined under the library: <cmath>. This function represents the upper limit. In many scenarios, we need to obtain the upper and lower limits of a function or value which can be easily done by applying this function.

 

Syntax

This ceil function is a default functions available in the standard library. The syntax of ceil is similar to be like a simple functions. There would be a parameter value that is passed inside the ceil functions to get the lowest possible value which is greater than or equal to the parametric value.

Data_type ceil(data_type variable_number);

It takes a single parameter value as its argument and returns an integer value. In general, there are many functions that are present which makes many problem statements easier to solve. One of the functions is “Ceil”.

And, in general, the ceil functions is used in parallel with the floor functions. These functions precisely give the integer value with respect to the lower and higher value for the floating-point number given in the parameter.

 

Examples of ceil functions in C++

Let us see different examples in getting to know the ”ceil” functions:

Example #1

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x;
int y;
cout<<“Enter any float number: “;
cin>>x;
y=ceil(x);
cout<<“The ceil function value of folating point number x is: “<<y;
}

Example #2

Now, let us see an example for the integer value in the parameter.

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x;
int y;
cout<<“Enter any integer number: “;
cin>>x;
y=ceil(x);
cout<<“The ceil function value of integer point number x is: “<<y;
}

Example #3

Below, let us have an example for both ceil and floor functions.

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x;
float y,z;
cout<<“Enter any integer number: “;
cin>>x;
y=ceil(x);
z=floor(x);
cout<<“The ceil function value of integer point number x is: “<<y<<endl;
cout<<“The floor function value of integer point number x is: “<<z;
}

Example #4

We use the data type as integer instead of float.

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x;
float y,z;
cout<<“Enter any integer number: ”
cin>>x;
y=ceil(x);
z=floor(x);
cout<<“The ceil function value of integer point number x is: “<<y<<endl;
cout<<“The floor function value of integer point number x is: “<<z;
}

 

Example #5

Now, to provide the ceil value for the integer numbers, instead of using the data type “int”, we can use “double”.

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x;
float y,z;
cout<<“Enter any integer number: “;
cin>>x;
y=ceil(x);
cout<<“The ceil function value of integer point number x is: “<<y<<endl;
}

 

Example #6

Here, let us check an example of the negative input values.

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x;
float y,z;
cout<<“Enter any integer number: “;
cin>>x;
y=ceil(x);
cout<<“The ceil function value of integer point number x is: “<<y<<endl;
}

Related Link

Install Windows Server 2016 on VMware Workstation step by step

Windows Server 2008 or 2008 R2 Domain Controllers

Install Windows Server 2016 Step by Step

How to Use Your Website to Get on the First Page of Google

​​​​​​

Download

 

 

One thought on “ceil function

Leave a Reply

Your email address will not be published. Required fields are marked *