GATE CS 2015, set 1 · Question 65 · Programming and Data Structures · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider the following pseudo code, where x and y are positive integers.
begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end
The post condition that needs to be satisfied after the program terminates is

  1. (A) {r = qx + y ∧ r < y}
  2. (B) {x = qy + r ∧ r < y}
  3. (C) {y = qx + r ∧ 0 < r < y}
  4. (D) {q + 1 < r - y ∧ y > 0}
Answer

Answer (B)

Answer from the official GATE CS 2015 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes