0

Where is my mistake?

You 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 #include <iostream> using namespace std; int main() { int a,b; cin >>a>>b; int arr[100][100]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { cin >> arr[i][j]; } } int max = arr[0][0]; int x = 0; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if (max < arr[i][j]) { max = arr[i][j]; x = i + 1; } } } cout << x; return 0; }

5th Oct 2020, 11:09 AM
Altyn
2 odpowiedzi
+ 1
The below thread, is the third copy on the same problem you described (snippet may vary). Is this a homework or a challenge somewhere? May I suggest to follow the below thread, instead of posting a similar problem? it'll do a favour in reducing duplicate questions. https://www.sololearn.com/Discuss/2530887/?ref=app
5th Oct 2020, 11:24 AM
Ipang