-
Consider the following pseudo code, where x and y are positive integers.
begin
q: = 0
r: = x
while r > y do
being
r: = r – y
q: = q + 1
end
end
The post condition that needs to be satisfied after the program terminates is
-
- {r = qx + y ∧ r < y}
- {x = qy + r ∧ r < y}
- {y = qx + r ∧ 0 < r < y}
- {q + 1 < r – y ∧ y > 0}
- {r = qx + y ∧ r < y}
Correct Option: B
The loop terminater when r < y. so, r < y is one post condition.
In each iteration q is incremented by 1 and y is subtracted from r. Initialvalue of r is x.
So, loop iterates | times and q will be equal to | |||
y | y |
and r = x% y ⇒ x = qy + r
So, (b) is correct answer.