Explanation
In this program, we need to calculate the sum of elements in each row and each column of the given matrix.

Above diagram shows the sum of elements of each row and each column of a matrix.
Algorithm
- Declare and initialize a two-dimensional array a.
- Calculate the number of rows and columns present in the array a and store it in variables rows and cols respectively.
- Maintain two variables sumRow and sumCol to store the sum of elements in the specific row and the sum of elements in specific column respectively.
- To calculate the sum of elements in each row:
- Two loops will be used to traverse the array where the outer loop selects a row, and the inner loop represents the columns present in the matrix a.
- Calculate the sum by adding elements present in a row.
- Display sumRow.
- Repeat this for each row.
- To calculate the sum of elements in each column:
- Two loops will be used to traverse the array where the outer loop select a column, and the inner loop represents the rows present in the matrix a.
- Calculate the sum by adding elements present in a column.
- Display sumCol.
- Repeat this for each column.
Input:
Matrix a = [1, 2, 3]
Output:
Sum of 1 row: 6
Sum of 2 row: 15
Sum of 3 row: 24
Sum of 1 column: 12
Sum of 2 column: 15
Sum of 3 column: 18
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: