Showing posts with label ceil and floor functions. Show all posts
Showing posts with label ceil and floor functions. Show all posts

Aug 13, 2020

Ceil and Floor Functions in C++ | C++ Language | Coding Winds

CEIL and FLOOR Functions in C++

Hello people, today we are going to read about the two mathematical pre-defined functions of <cmath> library of C++ language. These functions are very helpful in the problems of competitive programming. If you are familiar with basic mathematics then you won’t face any difficulty while understanding these functions.

Ceil and Floor, these are two architectural words which we use very often. Ceiling is like the inner face of top horizontal face and Flooring means the lower most horizontal face of any cuboidal structure.

For using these two functions we need to include the <cmath> library in C++ and <math.h> in C language.

CEIL Funciton :

int c = ceil(double a);

This function returns the smallest integer which is greater than or equal to ‘a’.

Look at some below given explanations to get a more clear picture about the working of this function.

If :

a is equal to 5.9 than c will be 6

a is equal to 5.1 than c will be 6

a is equal to 6 than also c will be 6

FLOOR Function :

int c = floor(double a);

This function returns the largest integer which is smaller than or equal to ‘a’

Look at some below given explanations to get a more clear picture about the working of this function.

If :

a is equal to 5.9 than c will be 5

a is equal to 5.1 than c will be 5

a is equal to 5 than also c will be 5