YouTip LogoYouTip

Cpp Examples Quotient Remainder

C++ Example - Quotient and Remainder

C++ Examples C++ Examples

Use 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 dividend: ";
    cin >> dividend;
    cout << "Enter divisor: ";
    cin >> divisor;
    quotient = dividend / divisor;
    remainder = dividend % divisor;
    cout << "Quotient = " << quotient << endl;
    cout << "Remainder = " << remainder;
    return 0;
}

The output of the above program is:

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

C++ Examples C++ Examples

← Cpp Examples SwappingCpp Examples Cout Cin β†’