C++程序 – 求商和余数
在这里,我们将看到如何使用c++程序找到商和余数。
示例:
Input: Dividend = 17, Divisor = 5
Output: Quotient = 3, Remainder = 2
Input: Dividend = 23, Divisor = 3
Output: Quotient = 7, Remainder = 2
模运算符将用于计算余数和商,除法运算符将用于计算除数。
Quotient = Dividend / Divisor;
Remainder = Dividend % Divisor;
下面是查找商和余数的c++程序:
// C++ program to find quotient
// and remainder
#include<bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
int Dividend, Quotient,
Divisor, Remainder;
cout << "Enter Dividend & Divisor: ";
cin >> Dividend >> Divisor;
Quotient = Dividend / Divisor;
Remainder = Dividend % Divisor;
cout << "The Quotient = " <<
Quotient << endl;
cout << "The Remainder = " <<
Remainder << endl;
return 0;
}
输出 :
注意: 如果除数是’ 0 ‘,那么它将显示一个ArithmeticException错误。