0

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,correct the error please */ #include <iostream> using namespace std; int main() { int n, m; int 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; }

5th Oct 2020, 10:25 AM
Azat Malgazhdar
Azat Malgazhdar - avatar
1 Réponse
+ 2
This is the third time you posted this problem. Please elaborate with the people who contributed an answer in your previous threads rather than reposting it. Help the community reduce duplicate questions ... https://www.sololearn.com/Discuss/2529322/?ref=app https://www.sololearn.com/Discuss/2528180/?ref=app
5th Oct 2020, 10:37 AM
Ipang