In: Computer Science
Design and implement a function with two input parameters, A and B. The functions then calculates the result of the floor division of A over B (A//B). You are not allowed to use the floor division operator. Look at here: https://simple.wikipedia.org/wiki/Division_(mathematics) - For instance the function for 20 and 6 will return 3.
Explanation:-
To calculate Ceil without using ceil() a function is created and in that we will use '/' operator between the 2 values and it will give us the ceil value.
Code is as follows:-
#include <iostream>
#include <bits/stdc++.h> // Header Files
using namespace std;
int calculateCeil(int a, int b) { // Function accepting two args. and calculating Ceil without using ceil()
int ans = a/b; // Variable storing the ceil value
return ans;
}
//Driver Function
int main() {
int a = 20;
int b = 6;
int ans = calculateCeil(a,b); // Calling the function to calculate ceil value and passing a & b as argument
cout<<"Ceil Value is : "<<ans; // Printing the ceil value
}
Output:-