15,667,829 members
See more:
how to divide larger number by smaller number and express answers using quotient and remainder rather than a fraction or decimal quotient. for example if i divide 7 by 2, answer would have been given 3 as a quotient and 1 as a remainder. Divide larger number by smaller.

example:
7 / 2 = 3 r 1
2 / 7 = 3 r 1

i have done this so far but i don't know to i can always divide larger number by smaller using if and else statement.

C++
```#include <iostream>
using namespace std;

int main() {

int large,small,quo,rem;
cout << "\nEnter 2 numbers to divide: ";
cin >> large >> small;
quo = large / small;
rem = large % small;
cout << ""<< quo;
cout << " r "<< rem;

return 0;
}```
Posted

## Solution 1

What you are doing is basically correct, using the '/' and '%' operators. As an alternative you can use the div and ldiv functions of the runtime library, which return the quotient and remainder in a structure. On some systems that might be slightly faster, because the remainder is usually a by-product of the division.

## Solution 2

If the `large` is smaller than `small`, swap them:
C++
```if(bigger < smaller)
{
int tmp = bigger;
bigger = smaller;
smaller = tmp;
}```

C++
```#include <iostream>

using namespace std;

int main()
{
int bigger, smaller;

cout << "Enter a number:" << endl;
cin >> bigger;

cout << "Enter another number:" << endl;
cin >> smaller;

if(bigger < smaller)
{
int tmp = bigger;
bigger = smaller;
smaller = tmp;
}

int q = bigger / smaller;
int r = bigger % smaller;

cout << "Result: " << q << endl;

if(r > 0)
cout << "Remainder: " << r << endl;

return 0;
}
</iostream>```

v2
danial khan 22-Oct-13 20:57pm
thank you very much for helping :) but the another problem is that i have make this program professional. Example if i divide 99 by 9 it shows the answer like this 11 r 0 but i don't want 0 it suppose to type just 11
Captain Price 22-Oct-13 21:09pm
then print the remainder only if it's greater than 0 :) I have edited the code.