209k views
2 votes
How many line ofoutput will be displayed by the following program fragment?

i=0;
do
{
for(j=0;j<4;j=j+1)
printf("%d\\",i+j);
i=i+1;
}
while(i<5);
A. 0
B. 7
C. 9
D. 16
E. 20

1 Answer

3 votes

Answer:

Hi!

Let's make a quick debug of the code:

i j Output

0+0 = 0

0+1 = 1

0+2 = 2

0+3 = 3

1+0 = 1

1+1 = 2

1+2 = 3

1+3 = 4

2+0 = 2

2+1 = 3

2+2 = 4

2+3 = 5

3+0 = 3

3+1 = 4

3+2 = 5

3+3 = 6

4+0 = 4

4+1 = 5

4+2 = 6

4+3 = 7

The total outputs is 20.

Step-by-step explanation:

In the first iterations of the loop for the final value of the i is 1 and the final condition to stop of the do while is (i < 5) , so the iteration of for continues many times until i break the condition.

(5*4 = 20)

And after that you get 20 outputs.

I hope it's help you.

User RSilva
by
4.9k points