算商和余数的c++代码
时间: 2023-11-04 16:08:42 浏览: 241
计算器的c++代码
以下是计算商和余数的 C++ 代码示例:
```c++
#include <iostream>
using namespace std;
int main() {
int dividend, divisor, 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 << endl;
return 0;
}
```
该程序首先要求用户输入被除数和除数,然后通过除法运算符 `/` 和模运算符 `%` 计算商和余数,并将结果打印输出。
阅读全文