ProgrammingHardProduct company OA
What is printed?
What is printed?
int A[2][2] = {{1, 2}, {3, 4}}, B[2][2] = {{0, 1}, {1, 0}}, C[2][2] = {0};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++) C[i][j] += A[i][k] * B[k][j];
printf("%d %d %d %d", C[0][0], C[0][1], C[1][0], C[1][1]);- A. 2 1 4 3
- B. 1 2 3 4
- C. 3 4 1 2
- D. 2 4 1 3
Correct answer: A. 2 1 4 3
Multiplying A on the right by the swap matrix B swaps A's columns: [[2, 1], [4, 3]]. B × A would swap rows instead ('3 4 1 2'), which is the usual mix-up of order.
More C Programming questions
- When should a variable be declared volatile?
- What is printed? c void f(int a, int n) { if (n <= 1) return; a[n - 2] += a[n - 1]; f(a, n - 1); } int main(void) { int a[] = {1, 2, 3…
- With a 32-bit unsigned int x, which expression has undefined behaviour?
- What is printed? c char s[] = "7392"; int n = 0; for (int i = 0; s[i]; i++) n = n 10 + (s[i] - '0'); printf("%d %d", n % 1000, n / 100 %…
- What is printed? c int f(int n) { if (n == 0) return 0; return (n & 1) + f(n >> 1) 10; } int main(void) { printf("%d", f(13)); }
- What is printed? c struct S { int a; int b; } s[] = {{1, 10}, {2, 20}, {3, 30}}; struct S p = s; int x = ++p->a; int y = (++p)->b; int z =…