c++ 实例 - 求商及余数
使用 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
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!