C++ Program to Find Quotient and Remainder of Two Integers Entered By User

In this C++ program, user is asked to enter two numbers and program calculates the quotient and remainder of two numbers entered by user.

First we need to become familiar with some basic terminologies of division operation.

  • The number which is being divided is called dividend.
  • The number by which we divide is called divisor.
  • The result of division is called quotient.
  • The number left over is called remainder.

In this C++ program, first we want to find the quotient of two numbers.  The quotient of two numbers is calculated by dividing the dividend by divisor. So, the formula for quotient is:

Quotient = Dividend / Divisor

The next part of our program is based on the question, How to find remainder in C++?

The remainder is calculated by using mod( % ) operator between two operands. So, the formula for remainder  is:

Remainder = Dividend % Divisor

Now, we have the all the necessary formulas and we can use them to build a C++ program to find quotient and remainder of two numbers entered by user.

 Recommended reading: How to add two numbers using classes in C++

C++ Code to Find Quotient and Remainder:

#include<iostream>
using namespace std;
int main()
{
	int quotient,remainder;
	int divisor,dividend;
	cout<<"ENTER DIVIDEND:";
	cin>>dividend;
	cout<<"ENTER DIVISOR:";
	cin>>divisor;
	quotient=dividend/divisor;
	remainder=dividend%divisor;
	cout<<"QUOTIENT="<<quotient<<endl;
	cout<<"REMAINDER="<<remainder;
	return 0;
}

Code Explanation:

First of all, we declared 4 variables named dividend,  divisor,  quotient & remainder. All these variables are of integer data type. We cannot declare them as float  because modulus ( % ) operator can never be applied on floating-type variables.

After that, we simply asked the user to enter the values of dividend and divider. We applied division operation on provided values and found the value of quotient. Next, we applied mod( % ) operator on provided values and found remainder of division.

 Recommended reading: Convert Years of Age into Months, Days, Hours And Minutes in C++

At the end, we simply printed the values of quotient and remainder on the screen.

Dry Run:

Let’s dry run this code to see how it works:

Suppose 48 and 5 are hypothetical values of dividend and divisor respectively.

Quotient = Dividend / Divisor = 48 / 5 =9

Remainder = Dividend / Divisor = 48 % 5 = 3

Output:

Quotient and remainder program in c++

If you liked this article, then I would really appreciate if you follow us on Twitter and Facebook.

If you have any question then you can ask me in comments. I would like to answer them.

You can also Click Here To Download Project Files.