Answer- Find ceil of a/b without using ceil() function
Input : a = 5, b = 4
Output : 2
Explanation: a/b = ceil(5/4) = 2
Input : a = 10, b = 2
Output : 5
Explanation: a/b = ceil(10/2) = 5
Formula for finding ceil value without using function:
ceilVal = (a+b-1) / b
Using simple maths, we can add the denominator to the numerator and subtract 1 from it and then divide it by denominator to get the ceiling value.
import java.io.*;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int val = (a + b - 1) / b;
System.out.println("The ceiling value of a/b is "
+ val);
}
}