Determinati elementele sa ale unei matrici cu n linii si m coloane (elemente minime pe linie si maxime pe coloana sau maxime pe linie si minime pe coloana)
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int main ()
{
int l,c,i,j,m[50][50],max_coloane[50],min_coloane[50],max_linii[50],min_linii[50],min,max;
cout<<"Nr.linii:";
cin>>l;
cout<<"Nr.coloane:";
cin>>c;
for(i=1;i<=l;i++)
for(j=1;j<=c;j++){
cout<<"m["<<i<<"]["<<j<<"]:";
cin>>m[i][j];}
cout<<"Matricea este:"<<endl;
for(i=1;i<=l;i++){
for(j=1;j<=c;j++)
cout<<m[i][j]<<" ";
cout<<endl;}
for(i=1;i<=l;i++){
max=-99999;
min=99999;
for(j=1;j<=c;j++)
{if (m[i][j]>max)
{max=m[i][j];
max_linii[i]=max;}
if (m[i][j]<min)
{min=m[i][j];
min_linii[i]=min;}
}}
for(j=1;j<=c;j++){
max=-99999;
min=99999;
for(i=1;i<=l;i++)
{if(m[i][j]>max)
{max=m[i][j];
max_coloane[j]=max;}
if (m[i][j]<min)
{min=m[i][j];
min_coloane[j]=min;}
}}
cout<<"Elementele sa sunt:"<<endl;
for(i=1;i<=l;i++)
for(j=1;j<=c;j++){
if(max_linii[i]==min_coloane[j] || min_linii[i]==max_coloane[j])
cout<<m[i][j]<<" "<<"de pe linia "<<i<<", coloana "<<j<<"."<<endl;}
return 0;
}