Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
