195k views
4 votes
Trace coding below

a = 1

b = 2

c = 5

while a < c

a = a + 1

b = b + c

endwhile

output a, b, c

1 Answer

5 votes

Answer:

Step-by-step explanation:

Initially, a is assigned the value 1, b is assigned the value 2, and c is assigned the value 5. The while loop is entered because a (1) is less than c (5).

In the first iteration of the while loop:

a is incremented by 1, so a becomes 2.

b is incremented by c (5), so b becomes 7.

In the second iteration of the while loop:

a is incremented by 1, so a becomes 3.

b is incremented by c (5), so b becomes 12.

In the third iteration of the while loop:

a is incremented by 1, so a becomes 4.

b is incremented by c (5), so b becomes 17.

In the fourth iteration of the while loop:

a is incremented by 1, so a becomes 5.

b is incremented by c (5), so b becomes 22.

At this point, the while loop is exited because a (5) is no longer less than c (5).

The output of the program will be:

5

22

5

User Jonas Chapuis
by
8.7k points