wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Matrix

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", matrix[1][2]); return 0; }
a)
Prints the element in the second row, third column
b)
Prints the element in the third row, second column
c)
Prints the sum of all elements in the matrix
d)
Causes a compilation error
2.
#include <stdio.h> int main() { int matrix1[2][2] = {{1, 2}, {3, 4}}; int matrix2[2][2] = {{5, 6}, {7, 8}}; int result[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { result[i][j] = matrix1[i][j] + matrix2[i][j]; } } printf("%d", result[1][1]); return 0; }
a)
Matrix Multiplication
b)
Matrix Addition
c)
Matrix Subtraction
d)
Transposition
3.
#include <stdio.h> int main() { int matrix[2][2] = {{1, 2}, {3, 4}}; printf("%d", *(&matrix[0][0] + 2)); return 0; }
a)
3
b)
2
c)
1
d)
4
4.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int i = 0; i < 3; i++) { for (int j = i+1; j < 3; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } printf("%d", matrix[2][0]); return 0; }
a)
Transposition
b)
Matrix Inversion
c)
Scalar Multiplication
d)
Identity Matrix
5.
#include <stdio.h> int main() { int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; int transpose[3][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { transpose[j][i] = matrix[i][j]; } } printf("%d", transpose[1][0]); return 0; }
a)
Transposes the matrix
b)
Finds the determinant of the matrix
c)
Multiplies the matrix by its transpose
d)
Causes a compilation error
6.
#include <stdio.h> int main() { int matrix[2][2] = {{1, 2}, {3, 4}}; int *ptr = matrix[0]; printf("%d", *(ptr + 2)); return 0; }
a)
3
b)
2
c)
1
d)
4
7.
#include <stdio.h> int main() { int matrix1[2][3] = {{1, 2, 3}, {4, 5, 6}}; int matrix2[3][2] = {{7, 8}, {9, 10}, {11, 12}}; int result[2][2] = {0}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { result[i][j] += matrix1[i][k] * matrix2[k][j]; } } } printf("%d", result[1][0]); return 0; }
a)
Matrix Addition
b)
Matrix Multiplication
c)
Matrix Subtraction
d)
Transposition
8.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", matrix[2][0]); return 0; }
a)
7
b)
8
c)
9
d)
Compilation error
9.
#include <stdio.h> int main() { int matrix[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++) { if (i != j) { matrix[i][j] = 0; } } } printf("%d", matrix[2][2]); return 0; }
a)
Transposition
b)
Diagonalization
c)
Matrix Inversion
d)
Scalar Multiplication
10.
What does the following code snippet do with a 2x2 matrix? #include <stdio.h> int main() { int matrix[2][2] = {{1, 2}, {3, 4}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { matrix[i][j] *= 2; } } printf("%d", matrix[1][0]); return 0; }
a)
Multiplies each element by 2
b)
Adds 2 to each element
c)
Transposes the matrix
d)
Causes a compilation error
11.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", matrix[2][1]); return 0; }
a)
6
b)
8
c)
5
d)
compilation error
12.
#include <stdio.h> int main() { int matrix[2][2] = {{1, 2}, {3, 4}}; printf("%d", matrix[1][1]); return 0; }
a)
2
b)
3
c)
4
d)
compilation error
13.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", matrix[2][1]); return 0; }
a)
6
b)
8
c)
5
d)
compiler error
14.
#include <stdio.h> int main() { int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d", matrix[1][2]); return 0; }
a)
3
b)
6
c)
5
d)
compiler error
15.
#include <stdio.h> int main() { int matrix[2][3] = {{8, 9, 10}, {2,5,8}}; printf("%d", matrix[0][2]); return 0; }
a)
2
b)
10
c)
11
d)
compiler error