procedure divide n positive integer while n 0 begin m 1n n
procedure divide (n: positive integer)
while n ? 0
begin
m := 1/n
n := n - 1
end
output(m)
A. This algorithm works and outputs 1/n.
B. When n=1 is the input, after the first iteration of the while loop we have m=1 and n=0.
C. When n=1 is the input, on the second iteration of the while loop a division by zero occurs.
D. This algorithm lacks definiteness since division by zero occurs.
E. This algorithm works and always outputs 1.
F. When n=1 is the input, the algorithm exits the while loop after the first iteration and outputs m=1.
Solution
A True
B False
C False
D True
E True
F True
