使用 C++ 获取用户的输入两个数字,并将两个数字相除,然后将商和余数输出到屏幕:
#include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "输入被除数: "; cin >> dividend; cout << "输入除数: "; cin >> divisor; quotient = dividend / divisor; remainder = dividend % divisor; cout << "商 = " << quotient << endl; cout << "余数 = " << remainder; return 0; }
以上程序执行输出结果为:
输入被除数: 13 输入除数: 4 商 = 3 余数 = 1