C++ Program to Find Quotient and Remainder

C++
// C++ program to find quotient
// and remainder
#include <iostream>
using namespace std;

// Driver code
int main()
{
    int Dividend, Quotient, Divisor, Remainder;

    cout << "Enter Dividend & Divisor: ";
    cin >> Dividend >> Divisor;

    // Check for division by zero
    if (Divisor == 0) {
        cout << "Error: Divisor cannot be zero." << endl;
    } else {
        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 show Error: Divisor cannot be zero.

Related Articles


C++ Program to Find Quotient and Remainder

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,

 

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;

Similar Reads

C++ Program to Find Quotient and Remainder

C++ // C++ program to find quotient // and remainder #include using namespace std; // Driver code int main() { int Dividend, Quotient, Divisor, Remainder; cout << "Enter Dividend & Divisor: "; cin >> Dividend >> Divisor; // Check for division by zero if (Divisor == 0) { cout << "Error: Divisor cannot be zero." << endl; } else { Quotient = Dividend / Divisor; Remainder = Dividend % Divisor; cout << "The Quotient = " << Quotient << endl; cout << "The Remainder = " << Remainder << endl; } return 0; }...

Contact Us