C++ Example - Calculate Quotient and Remainder

C++ Examples

Use C++ to get two numbers from user input, divide the two numbers, 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 execution is:

输入被除数: 13
输入除数: 4
商 = 3
余数 = 1

C++ Examples

other extensions