Consider the C program fragment below which is meant to divide $x$ by $y$ using repeated subtractions. The variables $x$, $y$, $q$ and $r$ are all unsigned int.
while (r >= y) { r=r-y; q=q+1; }
Which of the following conditions on the variables $x, y, q$ and $r$ before the execution of the fragment will ensure that the loop terminated in a state satisfying the condition $x==(y*q + r)$?
https://gateoverflow.in/8276/gate2015-1_33
Here, $x == ( y*q + r )$ says $q =$ quotient and $r =$ remainder. To divide a number with repeated subtraction, quotient should be initialized to $0$ and should be incremented for each subtraction. Initially $q=0 \Rightarrow r = x$. $\therefore$ Initial conditions should be C] $(q == 0) \ \&\& \ (r == x) \ \&\& \ (y > 0)$.
If we divide a number with 0 (zero), will result in undefined state. that's why we need to check y > 0 condition. And one more point unsigned integer range is 0 to 2^{n}-1.
https://gateoverflow.in/8276/gate2015-1-33
reverse question
we can solve by leting some values, as shown below:-
answer is C