This program displays every combination of three-digits start Declarations num digit1 = 0 num digit2 = 0 num digit3 = 0 while digit1 <= 9 while digit2 <= 9 while digit3 <= 9 output digit1, digit2, digit3 digit1 = digit1 + 1 endwhile digit2 = digit2 + 1 endwhile digit3 = digit3 + 1 endwhile stop Debugging 5-03 what needs to be fixed
// This
start
Declarations
num digit1 = 0
num digit2 = 0
num digit3 = 0
while digit1 <= 9
while digit2 <= 9
while digit3 <= 9
output digit1, digit2, digit3
digit1 = digit1 + 1
endwhile
digit2 = digit2 + 1
endwhile
digit3 = digit3 + 1
endwhile
stop
Debugging 5-03 what needs to be fixed ?
The program will not output all combinations of three digits because the variables digit2
and digit3
are not being reset to zero after each iteration of the nested loops. This means that the outer loop will only iterate once since digit2
and digit3
will remain at their maximum value after the first iteration of the inner loops.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps