edited by
15,701 views
54 votes
54 votes

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. $\{ r = qx + y \wedge r < y\}$
  2. $\{ x = qy  + r \wedge r < y\}$
  3. $\{ y = qx + r \wedge 0 < r < y\}$
  4. $\{ q + 1 < r - y \wedge y > 0\}$
edited by

7 Answers

1 votes
1 votes
r is remainder, y is the one dividing x and q is the result.

So, look for this : x = qy + r

P.S: Not standard method.
1 votes
1 votes

1. Loop will terminate when r<y

2. Every iteration updates as r-y​. So the loop iterates r/y times. 'r=x' is given. So we get x/y i.e x get divided by y. 

Hence, x=qy+r would be the second condition.

So, answer would by option B

0 votes
0 votes

the pseudo code divides $x$ with $y$ leaving remainder $r$ upto the point when remainder i.e $r<y$

as

$Dividend= Divisor*Quotient +Remainder$ and $remainder < divisor$

x=qy+r and r<y

option B

Answer:

Related questions

24 votes
24 votes
3 answers
3
Kathleen asked Sep 12, 2014
4,530 views
Consider the following PASCAL program segment:if i mod 2 = 0 then while i >= 0 do begin i := i div 2; if i mod 2 < 0 then i := i - 1; else i := i – 2; end;An appropria...