Examples of ceil function in C++

Examples of ceil function in C++
Techiio-author
Written by Sagar RabidasFebruary 12, 2022
6 min read
C++
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

Today we will discuss Examples of ceil function in C++

ceil function in C++

Ceil is a characteristic that provides the next feasible extra than or an equal integer number as output to a random range supplied because the enter inside the shape of a parameter. This feature is commonly described under the library: <cmath>. This characteristic represents the higher restriction. In many situations, we need to achieve the upper and lower limits of a feature or fee which can be without problems performed with the aid of making use of this function.

Syntax:-

This ceil function is a default function available in the standard library. The syntax of ceil is similar to being like a simple function. There would be a parameter value that is passed inside the ceil function 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, many functions are present which makes many problem statements easier to solve. One of the functions is “Ceil”.

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

Examples of ceil function in C++

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

Example #1

Code:

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

Code:

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

Code:

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

Code:

#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 ceiling value for the integer numbers, instead of using the data type “int”, we can use “double”.

Code:

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

Code:

#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;
}

C
C++
ceil function
ceil function in C++
C++ function
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance