102k views
0 votes
What is the output of this nested loop ? i = 4;

while( i >= 1)
{
j= 1;
while (j > = 1) {
cout << j;
j = j - 1;
}
cout << i << endl; i = i - 1;
}

User Asesh
by
8.0k points

1 Answer

3 votes

Final answer:

The output of the nested loop is a pattern of numbers being printed in separate lines.

Step-by-step explanation:

The output of the nested loop is as follows:

  1. The first iteration of the outer loop prints the numbers 1, 2, 3, and 4 in separate lines, followed by a line break.
  2. The second iteration of the outer loop prints the numbers 1, 2, and 3 in separate lines, followed by a line break.
  3. The third iteration of the outer loop prints the numbers 1 and 2 in separate lines, followed by a line break.
  4. The fourth and final iteration of the outer loop prints the number 1 in a line, followed by a line break.

User Benathon
by
8.2k points