ProgrammingVery hard

int a[4][4] = {0}; for (int i = 0; i < 4; i++) a[i][i] = a[i][3 - i] = 1; int c = 0; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) c += a[i][j]; printf("%d", c); What is printed?

  1. A. 4
  2. B. 6
  3. C. 8
  4. D. 2

Correct answer: C. 8

Each row sets two cells, (i, i) and (i, 3 - i). For a 4 x 4 matrix these are always different cells, so 4 rows x 2 cells = 8 ones.

More C Programming questions

Exams that ask this topic