Easy Tutorial
❮ Cpp Exceptions Handling Cpp Examples Prime Number ❯

C++ Example - Finding Quotient and Remainder

C++ Examples

Using C++ to get two numbers from the user, divide them, and then output the quotient and remainder to the screen:

Example

#include <iostream>
using namespace std;

int main()
{    
    int divisor, dividend, quotient, remainder;

    cout << "Enter the dividend: ";
    cin >> dividend;

    cout << "Enter the divisor: ";
    cin >> divisor;

    quotient = dividend / divisor;
    remainder = dividend % divisor;

    cout << "Quotient = " << quotient << endl;
    cout << "Remainder = " << remainder;

    return 0;
}

The above program produces the following output:

Enter the dividend: 13
Enter the divisor: 4
Quotient = 3
Remainder = 1

C++ Examples

❮ Cpp Exceptions Handling Cpp Examples Prime Number ❯