In this tutorial, we will write a C++ program to find the quotient and remainder of a given dividend and divisor.
The program asked the user to enter the numbers (divisor and dividend). And to compute and find the quotient and remainder, we will use the division(/) and modulus(%) operators.
C++ Program to Find Quotient and Remainder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> using namespace std; int main() { int denominator, numerator, quotient, remainder; cout << "Enter numerator: "; cin >> numerator; cout << "Enter denominator: "; cin >> denominator; quotient = numerator / denominator; remainder = numerator % denominator; cout << "\nQuotient: " << quotient << endl; cout << "Remainder: " << remainder; return 0; } |
Output:
Enter numerator: 20
Enter denominator: 10
Quotient: 2
Remainder: 0
Enter numerator: 15
Enter denominator: 4
Quotient: 3
Remainder: 3