Computer Science, asked by sahilss0410, 8 months ago

Seenu have a fruit shop. He is arranged the some set of fruits are column and row wise. Seenu needs to find which row and column has maximum number of fruits. Help him to find out.

INPUT & OUTPUT FORMAT:

Input consists of 2 integers and 1 2D-array. Integers correspond to the size of rows and columns.

SAMPLE INPUT & OUTPUT:

3

3

1 6 8

2 5 1

3 8 2

Sum of rows is 15 8 13

Row 1 has maximum sum

Sum of columns is 6 19 11

Column 2 has maximum sum​

Answers

Answered by bramarambarowthu
9

Answer:

#include<iostream>

using namespace std;

int main()

{

int m, n, row, col, sum = 0, row_ind = 0, col_ind = 0;

std::cin >> m >> n;

int row_arr[m];

int i, j;

int mat[m][n];

for(i = 0; i < m; i++)

{

for(j = 0; j < n; j++)

std::cin >> mat[i][j];

}

int z = 0;

for(row=0; row<m; row++)

{

sum = 0;

for(col=0; col<n; col++)

{

sum += mat[row][col];

}

std::cout << sum << "\n";

row_arr[z++] = sum;

}

int temp_row = row_arr[0];

for(i=1;i<m;i++)

{

if(temp_row < row_arr[i])

{

temp_row = row_arr[i];

row_ind = i;

}

}

sum = 0;

int y = 0;

int col_arr[n];

for (i = 0; i < n; ++i)

{

sum = 0;

for (j = 0; j < m; ++j)

{

sum = sum + mat[j][i];

}

col_arr[y++] = sum;

}

int temp_col = col_arr[0];

for(i=1;i<n;i++)

{

if(temp_col < col_arr[i])

{

temp_col = col_arr[i];

col_ind = i;

}

}

return 0;

}

Explanation: All test cases are satisfied

follow me for more answer

Answered by poojan
10

Language used : Python Programming  

Program :

rows=int(input())

columns=int(input())

l=[]

for i in range(rows):

  l.append(sum(list(map(int,input().split(' ')))))

for i in l:

  print(i)

Input :

3

3

1 2 3

7 3 1

7 4 1

Output :

6

11

12

Learn more :

1. Write a program to accept Basic salary of an employee. Calculate and display his gross salary based on the following information...

brainly.in/question/18744315

2.  Write the program for : Raju has a square-shaped puzzle made up of small square pieces containing numbers on them...

brainly.in/question/16956126

Attachments:
Similar questions