Computer Science, asked by rizwan2husain, 5 hours ago

algorithm for sum of each row element of matrix ?​

Answers

Answered by Riya1045
1

Algorithm

STEP 1: START.

STEP 2: DEFINE rows, cols, sumRow, sumCol.

STEP 3: INITIALIZE matrix a[][] ={{1, 2, 3},{4, 5, 6}, {7, 8, 9}}

STEP 4: rows = a.length.

STEP 5: cols = a[0].length.

STEP 6: REPEAT STEP 7 to STEP 10 UNTIL i<rows. // for(i=0; i<rows; i++)

STEP 7: SET sumRow =0.

STEP 8: REPEAT STEP 9 UNTIL j<cols.

Answered by sonam8423
1

Answer:

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.

Wall of Love

DS & Algo Bootcamp

Company-Specific Courses

FACE Prep Edge

Free Resources

Webinars

About Us

LOGIN

SIGN UP

Link copied to clipboard. Share away!

Dismiss

Program to find sum of elements in each row and each column of the given matrix and print the greatest of the same

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

Explanation:

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.

Similar questions