2D_Array_Practice_Questions
2D_Array_Practice_Questions
1. Matrix Transpose
Example:
Input:
Matrix:
123
456
789
Output:
Transpose:
147
258
369
2. Sum of Elements
Example:
Input:
Matrix:
123
456
789
Output:
Sum: 45
Example:
Input:
Matrix:
123
456
789
Output:
Row-wise Sum:
Row 1: 6
Row 2: 15
Row 3: 24
Column-wise Sum:
Column 1: 12
Column 2: 15
Column 3: 18
4. Matrix Multiplication
Write a program to multiply two matrices. Ensure the number of columns in the first matrix equals
Example:
Input:
Matrix A:
12
34
Matrix B:
56
78
Output:
Resultant Matrix:
19 22
43 50
Example:
Input:
Matrix:
100
010
001
Output:
6. Diagonal Sum
Write a program to find the sum of the primary and secondary diagonals of a square matrix.
Example:
Input:
Matrix:
123
456
789
Output:
7. Spiral Traversal
Example:
Input:
Matrix:
1 2 3
4 5 6
7 8 9
Output:
Spiral Traversal: 1 2 3 6 9 8 7 4 5