The algorithm implements integer division of x by y using repeated subtraction, where q represents the quotient and r represents the remainder.
Loop Invariant:
At the start, q=0 and r=x, so the relation:
holds initially (x=0⋅y+x).
In each iteration:
rnew=r−y,qnew=q+1 qnewy+rnew=(q+1)y+(r−y)=qy+r=x Thus, the invariant x=qy+r is preserved across all iterations.
Loop Termination Condition:
The loop terminates when the condition r≥y is false, which means:
Post-condition:
Combining the loop invariant with the negation of the loop guard yields:
{x=qy+r∧r<y}
Hence, option (B) is correct.