- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ceil and floor functions in C++
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
#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
#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