+ 2
Find quotient and remainder
2 ответов
+ 5
For quotient we use / operator and for remainder we use % operator in c++
e.g.
int a=10,b=3;
int c = a/b; // this will give 3
int d= a%b; // this will give 1
cout<<c<<" "<<d;
Output:
3 1
+ 5
#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;
}
Output
Enter dividend: 13 Enter divisor: 4 Quotient = 3 Remainder = 1