考虑下面的伪代码,其中x和y是正整数。
begin
q := 0
r := x
while r >= y do
begin
r := r – y
q := q + 1
end
end
程序终止后需要满足的发布条件是
(A) {r = qx + y∧r
说明:给定的伪代码对给定的正整数x和y执行以下操作。
1) It initializes r as x.
2) It repeatedly subtracts y from r until r becomes
smaller than y. For every subtraction, it
increments count q.
3) Finally r contains remainder, i.e., x%y and q contains
⌊x/y⌋
请参阅下面的带注释的伪代码。
begin
q := 0 // q is going to contain floor(x/y)
r := x // r is going to contain x % y
// Repeatedly subtract y from x.
while r >= y do
begin
r := r – y
q := q + 1
end
end
这个问题的测验