ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, r[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) r[j][2 - i] = m[i][j];
printf("%d %d %d", r[0][0], r[0][2], r[2][0]);- A. 3 9 1
- B. 1 7 3
- C. 7 9 1
- D. 7 1 9
Correct answer: D. 7 1 9
Row i of m becomes column 2 − i of r, which rotates the matrix 90° clockwise: r is 7 4 1 / 8 5 2 / 9 6 3. So r[0][0] = 7, r[0][2] = 1 and r[2][0] = 9. '3 9 1' is the anticlockwise rotation.
More C Programming questions
- What is printed? c const char s = "banana", p = s; int c = 0; while ((p = strchr(p, 'a')) != NULL) { c++; p++; } printf("%d", c);
- Assume IEEE-754 double. What is printed? c printf("%d %d", 0.1 + 0.2 == 0.3, 0.5 + 0.25 == 0.75);
- Assume 4-byte int. What is printed? c printf("%d %d", sizeof(int) -1 < 0, (int)sizeof(int) -1 < 0);
- What is printed? c Bool b = 0.5; printf("%d %d", b + 2, (Bool)256);
- What is printed? c int c = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (j == 1) break; c++; } printf("%d", c);
- With 4-byte int, what is printed? c int a[4] = {1, 2, 3, 4}; char c = (char )a; int p = (int )(c + 8); printf("%d %td", p, p - a);