ProgrammingVery hardTCS NQT · Infosys
What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program.
What is the trace of the matrix product A * B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program.
#include <stdio.h>
int main(void) {
int A[2][2] = {{1, 2}, {3, 4}}, B[2][2] = {{5, 6}, {7, 8}}, 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", C[0][0] + C[1][1]);
}- A. 70
- B. 68
- C. 69
- D. 72
Correct answer: C. 69
C[0][0] = 1*5 + 2*7 = 19 and C[1][1] = 3*6 + 4*8 = 50, so the trace is 69.
More C Programming questions
- How many elements of {0, 2, 1, 3, 4, 7, 6} equal their own index? Count with this program. c #include <stdio.h> int main(void) { int a[] =…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {2, 7, 1}; int e = a + sizeof a / sizeof a[0] - 1; printf("%d", e); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int a[4]; printf("%ld", (long)((char )&a[2] - (char…
- How many valid strings of n = 3 pairs of parentheses are there? The program counts them recursively. What is printed? c #include <stdio.h>…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { return (const unsigned char )a - (const…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xFF & ~0x1Cu; printf("%u", x); }