Task is to find the column number(index) that have maximum sum of it's elements
/* Input First line N and M (1<=N,M<=100). Then NxM table is given(all number are integers) Output The index of the column with maximum sum of it's elements. Sample input: 3 4 1 2 3 1 1 5 6 1 1 1 8 1 Sample output: 3 What is wrong? */ #include <iostream> using namespace std; int main() { int n, m,max =0; cin >> n >> m; int aza[100][100]; for (int i = 1; i <= n; i++) { for (int j = 1;j <= m; j++) { cin >> aza[i][j]; } } for (int j = 1; j <= m; j++) { int sum = 0; for (int i = 1; i <= n; i++) { sum+= aza[i][j]; } } int maxind = 0; for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { if (max < aza[i][j]) { max = aza[i][j]; maxind = i; } } } cout << maxind; }