Computer Science, asked by ayushkarwa08, 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.

Answers

Answered by madeducators2
1

Source code for finding the maximum and minimum number of fruits in each row and column

Explanation:

*Note: It has been assumed that the compiler being used is C++.

The following code can be customized to get the desired result:

#include<iostream.h>

#include<limits.h>

using namespace std;

const int n = 3;

const int m = 3;

void display(int result[], int n)

{

   int i;

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

   {

       cout << result[i] << ” “;

   }

}

void mini_row(int mat[][3], int m, int n)

{

   int i = 0, j;

   int min = INT_MAX;

   int result[m];

   while (i < m)

   {

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

       {

           if (mat[i][j] < min)

           {

               min = mat[i][j];

           }

       }

       result[i] = min;

       min = INT_MAX;

       i++;

   }

   display(result, m);

}

int main()

{

   int i, j;

   int mat1[m][n];

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

   {

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

           cin >> mat1[i][j];

   }

   mini_row(mat1,m,n);

   return 0;

}

Answered by tarunp537
5

Answer:

#include<iostream>

using namespace std;

int main()

{

   int row,col;

   std::cin>>row;

   std::cin>>col;

   int arr[row][col];

   for( int i = 0 ; i < row ; i++ )

   {

       for( int j = 0 ; j < col ; j++ )

       {

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

       }

   }

   //---------------------------------

   int r[row];

   int rowtotal;

   int rowindex = 0;

   for( int i = 0 ; i < row ; i++ )

   {

       rowtotal = 0;

       for( int j = 0 ; j < col ; j++ )

       {

           rowtotal = rowtotal + arr[i][j];

       }

       r[rowindex] = rowtotal;

       rowindex++;

   }

   std::cout<<"Sum of rows is";

   for( int i = 0 ; i < rowindex ; i++ )

   {

       std::cout<<" "<<r[i];

   }

   int max;

   int tempindex = 0;

   max = r[0];

   for( int i = 0 ; i < rowindex ; i++ )

   {

       if(max < r[i])

       {

           max = r[i];

           tempindex = i;

       }

   }

   std::cout<<"\nRow "<<(tempindex+1)<<" has maximum sum\n";

   //---------------------------------

   int c[col];

   int coltotal;

   int colindex = 0;

   for( int i = 0 ; i < col ; i++ )

   {

       coltotal = 0;

       for( int j = 0 ; j < row ; j++ )

       {

           coltotal = coltotal + arr[j][i];

       }

       c[colindex] = coltotal;

       colindex++;

   }

   std::cout<<"Sum of columns is";

   for( int i = 0 ; i < rowindex ; i++ )

   {

       std::cout<<" "<<c[i];

   }

   int cmax;

   int tempcindex = 0;

   cmax = c[0];

   for( int i = 0 ; i < colindex ; i++ )

   {

       if(cmax < c[i])

       {

           cmax = c[i];

           tempcindex = i;

       }

   }

   std::cout<<"\nColumn "<<(tempcindex+1)<<" has maximum sum";

   //---------------------------------

   return 0;

}

Explanation:

Similar questions