Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (j == 2)
break;
printf("%d%d ", i, j);
}
}
printf("\n");
return 0;
}
- A 11 21 31 Correct
- B 11
- C 11 12 13
- D 11 21 31 12
Correct Answer: Option A
For each i, the inner loop prints j = 1 and breaks at j = 2. break leaves only the inner loop, so the outer loop continues with the next i.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!