ProgrammingHard
int c = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < i; j++) printf("x"), c++; printf("%d", c); What is printed?
- A. 2
- B. 3
- C. 4
- D. 6
Correct answer: B. 3
For i = 0 nothing runs, for i = 1 one x is printed and for i = 2 two more, giving 3 in total.
More C Programming questions
- int i = 0, c = 0; while (i i < 50) { c++; i++; } printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i++) if (i % 7 == 0) c++; printf("%d", c); What is printed?
- int cnt = 0; for (int i = 0; i < 10; i += 3) cnt++; printf("%d", cnt); What is printed?
- int i = 0, j = 10, cnt = 0; while (i < j) { i++; j--; cnt++; } printf("%d", cnt); What is printed?
- unsigned int i; for (i = 10; i >= 0; i--) { } What is the behaviour of this loop?
- Which C code correctly counts the digits of n = 10^9 in a fast enough way for many queries?