ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
int t = m[i][j]; m[i][j] = m[j][i]; m[j][i] = t;
}
printf("%d %d", m[0][1], m[2][0]);- A. 2 3
- B. 2 7
- C. 4 3
- D. 4 7
Correct answer: B. 2 7
Both loops run over the full matrix, so every off-diagonal pair is swapped twice, once at (i, j) and again at (j, i), which puts it back. The matrix ends unchanged. An in-place transpose must loop j from i + 1 only.
More C Programming questions
- What is printed? c int x = 5; x = x << 2 >> 1; printf("%d", x);
- What is printed? c int x = 9, y = 0; if (x = y == 0) printf("A%d", x); else printf("B%d", x);
- What is printed? c int f(int a, int b) { return a 10 + b; } int main(void) { printf("%d", f((1, 2), 3)); }
- What is printed? c int x = 0; if (x == 1); x += 5; printf("%d", x);
- What is printed? c int inc(int x) { return x + 1; } int dec(int x) { return x - 1; } int (pick(int c))(int) { return c ? inc : dec; } int…
- What is printed? c #include <limits.h> printf("%u %d", UINTMAX + 1u, UINTMAX == -1);