The following program segment is an attempt to compute the quotient (forgetting any remainder) of two positive integers (a dividend and a divisor) by counting the number of times the divisor can be subtracted from the dividend before what is left becomes less than the divisor. For instance, 7⁄3 should produce 2 because 3 can be subtracted from 7 twice. Is the program correct? Justify your answer.
Count ← 0;
Remainder ← Dividend;
repeat (Remainder ← Remainder – Divisor;
Count ← Count + 1)
until (Remainder < Divisor)
Quotient ← Count.
Here is program:
int main()
{
int Quotient;
int Count;
int Remainder;
int Divisor;
cin >> Quotient;
cin >> Divisor;
Count = Quotient / Divisor;
Remainder = Quotient % Divisor;
}
Comments
Leave a comment