Consider the C program fragment below which is meant to divide \(x\) by \(y\)…

GATE · 2017 · CS · Set 2 · Computer Science & IT

Consider the C program fragment below which is meant to divide xx by yy using repeated subtractions. The variables x,y,qx,y,q and rr are all unsigned int.

while (r >= y) { r=r-y; q=q+1; }

Which of the following conditions on the variables   x,y,qx,y,q and rr before the execution of the fragment will ensure that the loop terminated in a state satisfying the condition x==(y∗q+r)x==(y*q + r) ?

  1. A.

    (q==r) && (r==0)(q==r) \ \&\& \ (r==0)

  2. B.

    (x>0) && (r==x) && (y>0)(x>0) \ \&\& \ (r==x) \ \&\& \ (y>0)

  3. C.

    (q==0) && (r==x) && (y>0)(q==0) \ \&\& \ (r==x) \ \&\& \ (y >0)

  4. D.

    (q==0) && (y>0)(q==0) \ \&\& \ (y>0)

Attempted by 396 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…