Link copied to clipboard. Share away!

Dissmis

Published on 10 Mar 2020

Program to find the sum of elements in each row and each column of the given matrix and print the greatest of the same is discussed here. Input the matrix and find the sum of each row and each column and display the row having the greatest sum and also the column having the greatest sum.

For example, consider the matrix

mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

Sum of row 1 = 1 + 2 + 3 = 6

Sum of row 2 = 4 + 5 + 6 = 15

Sum of row 3 = 7 + 8 + 9 = 24

**Row 3 is having the greatest sum.**

Sum of column 1 = 1 + 4 + 7 = 12

Sum of column 2 = 2 + 5 + 8 = 15

Sum of column 3 = 3 + 6 + 9 = 18

**Column 3 is having the greatest sum.**

- Input the number of rows and columns of the matrix.
- Input the matrix elements.
- Traverse the matrix and find the sum of each row and each column and display them.
- Find the row having the greatest sum and display it.
- Find the column having the greatest sum and display it.

C

C++

Java

Python 3

Output

Enter the order of the matrix : 3 3

Input the matrix elements :

1 2 3

4 5 6

7 8 9

Sum of rows is 6 15 24

Row 3 has maximum sum

Sum of columns is 12 15 18

Column 3 has maximum sum

Input the matrix elements :

1 2 3

4 5 6

7 8 9

Sum of rows is 6 15 24

Row 3 has maximum sum

Sum of columns is 12 15 18

Column 3 has maximum sum

*Recommended Programs*

If you have any feedback about this
article and want to improve this, please write to **enquiry@faceprep.in**

×