In this C++ example, you will learn to find quotient and remainder of a given dividend and divisor.

Quotient and Remainder are parts of division along with dividend and divisor.
The number which we divide is known as the dividend. The number which divides the dividend is known as the divisor. The result obtained after the division is known as the quotient and the number left over is the remainder.
dividend = divisor * quotient + remainder
For Example: If 15 is divided by 7, then 2 is the quotient and 1 is the remainder. Here, 15 is the dividend and 7 is the divisor.
Finding Quotient and Remainder are some of the basic Mathematical operations, Here we’ll learn how to implement it in Programming. In this program, to Find Quotient and Remainder, the user is asked to enter two integers (divisor and dividend) and computes the quotient and remainder.
To compute quotient and remainder, both divisor and dividend should be integers.

Program to Compute quotient and remainder

#include <iostream>
using namespace std;
int main() {    
   int divisor, dividend, quotient, remainder;
   dividend = 15;
   divisor = 7;
   quotient = dividend / divisor;
   remainder = dividend % divisor;
   cout << "Dividend is " << dividend <<endl;
   cout << "Divisor is " << divisor <<endl;
   cout << "Quotient is " << quotient << endl;
   cout << "Remainder is " << remainder;
   return 0;
}



In the above program, the quotient is obtained by dividing the dividend by the divisor. The remainder is obtained by using the modulus operator on dividend and divisor.
quotient = dividend / divisor;
remainder = dividend % divisor;
After that the dividend, divisor, quotient and remainder are displayed.
cout << "Dividend is " << dividend <<endl;
cout << "Divisor is " << divisor <<endl;
cout << "Quotient is " << quotient << endl;
cout << "Remainder is " << remainder;

Post a Comment

 
Top