ProgrammingModerate
A 5 x 5 grid is stored as an int matrix. Which expression gives the number of cells on its main diagonal?
- A. 4
- B. 10
- C. 25
- D. 5
Correct answer: D. 5
The main diagonal cells are (i, i) for i from 0 to 4, so there are five of them.
More C Programming questions
- int n = 4; int m[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i][j] = i + j; printf("%d", m[3][3]); What is printed?
- Which statement about passing a 2D array to a function is correct in C99?
- int a[3][3]; printf("%zu", sizeof a[0][0] 3 3); What is printed with 4-byte int?
- A 2D grid of 1000 x 1000 is stored as int g[1000][1000] global. Roughly how many bytes does it take with 4-byte int?
- int d[2][3] = {1, 2, 3, 4, 5, 6}; printf("%d", d[1][0]); What is printed?
- int m[2][2] = {{1, 2}, {3, 4}}; int t[2][2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) t[j][i] = m[i][j]; printf("%d"…