2dArrays_homework
2dArrays_homework
1. 2D Array Traversal
✏️ Write a Python or Java program to complete the following tasks.
a) Print a 2D Array in Matrix Format
i) Write a program that prints the following 2D array as a matrix:
ii) create a function that takes in any 2D array and prints it in a matrix format
Given array:
1 2 3
4 5 6
7 8 9
Expected Output:
1 2 3
4 5 6
7 8 9
Expected Output:
Expected Output:
Row 1 sum = 18
Row 2 sum = 14
Row 3 sum = 13
Expected Output:
3. Special Challenges
🎯 Challenge your understanding with these problems:
(if you can do these i would be confident in your knowledge of loops, arrays and Decomposition)
a) Transpose of a Matrix
Write a program to find the transpose of a given 3×3 matrix.
(The transpose is obtained by swapping rows and columns.)
Example Input:
1 2 3
4 5 6
7 8 9
1 4 7
2 5 8
3 6 9
Example Input:
1 2 3
4 5 6
7 8 9
Expected Output:
Example Input:
Enter row (0-2): 1
Enter column (0-2): 2
Enter value (X/O): X
Expected Output:
_ _ _
_ _ X
_ _ _