Search⌘ K
AI Features

Loop Up and Down

Explore the behavior of loops in C programming by analyzing puzzle code. Learn to predict output and deepen your understanding of loop mechanics in practical contexts.

We'll cover the following...

Puzzle code

Read carefully the code given below:

C++
#include <stdio.h>
int main()
{
int u,d;
for( u=0, d=0; u<11; u++, d-- )
printf("%2d %2d\n", u, d);
return(0);
}

Your task: Guess the output

Attempt the following test to assess your understanding.

Technical Quiz
1.

What is the expected output of the above code?

A.

0 0
1 -1
2 -2
3 -3
4 -4
5 -5
6 -6
7 -7
8 -8
9 -9
10 -10

B.

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

C.

0 0
2 -2
4 -4
6 -6
8 -8
10 -10

D.

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9


1 / 1

Let's discuss the code and output together in the next lesson.