- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Find ceil of a/b without using ceil() function in C++.
Here we will see how to get the ceiling value of a/b without using the ceil() function. If a = 5, b = 4, then (a/b) = 5/4. ceiling(5/4) = 2. To solve this, we can follow this simple formula −
$$ceil\lgroup a,b\rgroup=\frac{a+b-1}{b}$$
Example
#include<iostream> using namespace std; int ceiling(int a, int b) { return (a+b-1)/b; } int main() { cout << "Ceiling of (5/4): " << ceiling(5, 4) <<endl; cout << "Ceiling of (100/3): " << ceiling(100, 3) <<endl; cout << "Ceiling of (49/7): " << ceiling(49, 7) <<endl; }
Output
Ceiling of (5/4): 2 Ceiling of (100/3): 34 Ceiling of (49/7): 7
- Related Articles
- PHP ceil() Function
- ceil() function in PHP
- floor() and ceil() function Python
- Find floor and ceil in an unsorted array using C++.
- Finding Floor and Ceil of a Sorted Array using C++ STL
- Ceil and floor functions in C++
- Floor and Ceil from a BST in C++
- Display the result difference while using ceil() in JavaScript?
- Java ceil() method with Examples
- Return the ceil of the inputs in Numpy
- Return the ceil of a specific array element in Numpy
- Python – PyTorch ceil() and floor() methods
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- Return the ceil value of the array elements in Numpy
- Return the ceil of the array elements and store the result in a new location in Numpy

Advertisements