GATE CS 2017 (Afternoon) — Question 37

Programming in CData Types, Syntax, Control Structures, LoopsMCQ2 marks · −2/3 if wrongMedium

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.
c
1while (r >= y)
2{
3    r = r - y;
4    q = q + 1;
5}
6
Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition \(x == (y \times q + r)\)?
  1. A
    \((q == r) \text{ \&\& } (r == 0)\)
  2. B
    \((x > 0) \text{ \&\& } (r == x) \text{ \&\& } (y > 0)\)
  3. C
    \((q == 0) \text{ \&\& } (r == x) \text{ \&\& } (y > 0)\)
  4. D
    \((q == 0) \text{ \&\& } (y > 0)\)
Practise the full 2017-AN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAWhat rank do your marks get?GATE score, likely All-India Rank and qualifying marks for your category.
Practise more on Data Types, Syntax, Control Structures, LoopsTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group