# ceil() function with example in C++

C++ ceil() function: Here, we are going to learn about the ceil() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 27, 2019

## C++ ceil() function

ceil() function is a library function of cmath header, it is used to find the roundup (upward) value of the given number, it accepts a number and returns the smallest integral value that is not less than to the given number.

Syntax of ceil() function:

```    ceil(x);
```

Parameter(s): x – is the number whose value to round up.

Return value: double – it returns double type value that is the rounded up value of the given number.

Example:

```    Input:
float x = 2.3;
Function call:
ceil(x);
Output:
3

Input:
float x = 3.8
Function call:
ceil(x);
Output:
4
```

### C++ code to demonstrate the example of ceil() function

```// C++ code to demonstrate the example of
// ceil() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
float x;

//input the number
cout<<"Enter a float value: ";
cin>>x;

//printing the round up value
cout<<"ceil("<<x<<"): "<<ceil(x)<<endl;

return 0;
}
```

Output

```First run:
Enter a float value: 2.3
ceil(2.3): 3

Second run:
Enter a float value: 3.8
ceil(3.8): 4

Third run:
Enter a float value: -2.3
ceil(-2.3): -2

Fourth run:
Enter a float value: -3.8
ceil(-3.8): -3
```

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates