# Floor and ceiling functions in c/c++ language

**CEILING**:

Function Declaration: double ceilf(double);

this function rounds a number up. It returns the smallest integer greater than or equal to x.

Flooring:

Function Declaration:double floor(double x)

this function rounds a number up. returns the largest integer value less than or equal to x.

Required Header: #include <cmath>

1 2 3 |
/* (c) wikistack.com Copy or publish or modification is allowed with same copyright */ |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include<iostream> #include<cmath> using namespace std; int main() { double n = 2.4; double result = 0; double result_2 = 0; result = ceilf(n); cout << "CEILING" << endl; cout << "Ininitial number = " << n << endl; cout << "Initial number rounded up = " << result << endl; result_2 = floor(n); cout << "Flooring" << endl; cout << "Initial number =" << n << endl; cout << "Inintial number rounded up =" << result_2 << endl; return 0; } |

output:

**CEILING**

** Ininitial number = 2.4**

** Initial number rounded up = 3**

** Flooring**

** Initial number =2.4**

** Inintial number rounded up =2**

## Leave a Reply