# Ceil and floor functions in C++

C++ProgrammingServer Side Programming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

## The ceil Function

The ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.

Here is the syntax of ceil function in C++ language,

double ceil(double x);
float ceil(float x);

Here is an example of ceil function in C++ language,

## Example

Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main() {
float var = 1234.25;
float res;
res = ceil(var);
cout << "Ceil value of " << var << " = " << res << endl;
return 0;
}

## Output

Ceil value of 1234.25 = 1235

## The floor Function

The floor function returns the largest possible integer value which is equal to the value or smaller than that. This function is also declared in “cmath” header file in C++ language. It takes single value whoes floor value is to be calculated. The datatype of variable should be double/ float/ long double only.

Here is the syntax of floor function in C++ language,

double floor(double x);
float floor(float x);

Here is an example of floor in C++ language,

## Example

Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main() {
float var = 211.876;
float res;
res = floor(var);
cout << "Floor value of " << var << " = " << res << endl;
return 0;
}

## Output

Floor value of 211.876 = 211