The remainder is the integer left over after dividing one integer by another. The quotient is the quantity produced by the division of two numbers.
(7/2) = 3
In the above expression 7 is divided by 2, so the quotient is 3 and the remainder is 1.
Approach: Divide the dividend by the divisor using / operator. Both dividend and divisor can be of any type except string, the result will also be computed accordingly. Get the remainder using % operator.
Expressions used in program to calculate quotient and remainder:
quotient = dividend / divisor; remainder = dividend % divisor;
Note: The program will throw an ArithmeticException: / by zero when divided by 0.
Consider Dividend = 100 and Divisor = 6
Quotient = 100/6 = 16
Remainder = 100%6 = 4
Below programs illustrate the above approach:
The Quotient is = 61 The Remainder is = 7
Program 2: For a negative number.
The Quotient is = -94 The Remainder is = -4
Program 3: This program will throw an ArithmeticException as the divisor = 0.
Exception in thread "main" java.lang.ArithmeticException: / by zero at QuotientAndRemainder.main(QuotientAndRemainder.java:7)
- C Program to Compute Quotient and Remainder
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Find the remainder when First digit of a number is divided by its Last digit
- BigInteger remainder() Method in Java
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Program to find Perimeter / Circumference of Square and Rectangle
- Program to find greater value between a^n and b^n
- Program to find the Area and Volume of Icosahedron
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Program to find Length of Bridge using Speed and Length of Train
- C/C++ program to find the size of int, float, double and char
- Program to find the diameter, cycles and edges of a Wheel Graph
- Program to find volume and surface area of pentagonal prism
- Program to find the Sum of each Row and each Column of a Matrix
- Program to find the Area and Perimeter of a Semicircle
- Program to find Surface Area and Volume of Octagonal Prism
- Python program to sort and find the data in the student records
- Structure and Members of the Java Program
- Compilation and Execution of a Java Program
- Program to find sum of elements in a given array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.