Remainder c++ – C++ Program to Find Quotient and Remainder

Remainder c++: In the previous article, we have discussed C++ Program to Read an Integer and Character and Print on Screen. In this article, we will see C++ Program to Find Quotient and Remainder.

C++ Program to Find Quotient and Remainder

  • Write a program in C++ to find quotient and remainder or two numbers.
  • How to find remainder and quotient of two numbers using / and % operator

To find the quotient and remainder or two numbers, we will first take two integers as input from user using cin and stores them in two local variables. Let the two input numbers be A and B. To find quotient and remainder of A/B we will use division(/) and modulus(%) operator.

Operator Description Syntax Example
/ Divides numerator by denominator a / b 15 / 5 = 3
% Returns remainder after an integer division a % b 16 % 5 = 1

C++ program to find quotient and remainder when an integer is divided by another integer

C++ program to find quotient and remainder when an integer is divided by another integer

/*
* C++ Program to Find Quotient and Remainder of integer division
*/
#include <iostream>
 
using namespace std;
 
int main() {
     
    int numerator, denominator, quotient, remainder;
    cout << "Enter Numerator\n";
    cin >> numerator;
    cout << "Enter Denominator\n";
    cin >> denominator;
     
    quotient = numerator/denominator;
    remainder = numerator%denominator;
     
    cout << "Quotient is " << quotient << endl;
    cout << "Remainder is " << remainder;
 
    return 0;
 
}

Output

Enter Numerator
10
Enter Denominator
2
Quotient is 5
Remainder is 0

Enter Numerator
13
Enter Denominator
3
Quotient is 4
Remainder is 1

Access the online Sample C++ Programs list from here and clear all your queries regarding the coding and give your best in interviews and other examinations.