Open In App

C++ Program to Find Quotient and Remainder

Last Updated : 03 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Here, we will see how to find the quotient and remainder using a C++ program.

The quotient is the result of dividing a number (dividend) by another number (divisor). The remainder is the value left after division when the dividend is not completely divisible by the divisor. For example,

Quotient and Remainder in C++

The Modulo Operator will be used to calculate the Remainder and Division Operator will be used to calculate the Quotient.

Quotient = Dividend / Divisor;

Remainder = Dividend % Divisor;

C++ Program to Find Quotient and Remainder

C++




// C++ program to find quotient
// and remainder
#include <bits/stdc++.h>
using namespace std;
  
// Driver code
int main()
{
    int Dividend, Quotient, Divisor, Remainder;
  
    cout << "Enter Dividend & Divisor: ";
    cin >> Dividend >> Divisor;
  
    Quotient = Dividend / Divisor;
    Remainder = Dividend % Divisor;
  
    cout << "The Quotient = " << Quotient << endl;
    cout << "The Remainder = " << Remainder << endl;
    return 0;
}


Output

Enter Dividend & Divisor: The Quotient = 0
The Remainder = 32767

Complexity Analysis

  • Time Complexity: O(1)
  • Auxiliary Space: O(1)

Note: If Divisor is ‘0’ then it will be showing an ArithmeticException Error.

Related Articles


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads