 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 