Find column with maximum sum in a Matrix using C++.

Suppose we have a matrix of size M x N. We have to find the column, that has a maximum sum. In this program we will not follow some tricky approach, we will traverse the array column-wise, then get the sum of each column, if the sum is the max, then print the sum and the column index.

Example

#include
#define M 5
#define N 5
using namespace std;
int colSum(int colIndex, int mat[M][N]){
   int sum = 0;
   for(int i = 0; i maxSum) {
         maxSum = sum;
         index = i;
      }
   }
   cout 

Output

Index: 4, Column Sum: 31
Updated on: 2019-10-29T11:44:18+05:30

520 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements