Se considera o matrice An*m cu elemente numere intregi. Sa se determine linia (liniile) din matrice care contine cele mai multe elemente nenule.

#include<iostream.h>
void main(void)
{
int a[30][30],n,m,i,j,max,nr;
cout<<"Dati numarul de linii n = ";cin>>n;
cout<<"Dati numarul de coloane m = ";cin>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cout<<"a["<<i<<","<<j<<"]= ";
cin>>a[i][j];
}
cout<<endl<<"Matricea A are elementele:"<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++) cout<<a[i][j]<<" ";
cout<<endl;
}
max=0;
for(i=1;i<=n;i++)
{
nr=0;
for(j=1;j<=m;j++)
if(a[i][j]!=0) nr++;
if(max<nr) max=nr;
}
for(i=1;i<=n;i++)
{
nr=0;
for(j=1;j<=m;j++)
if(a[i][j]!=0) nr++;
if(max==nr) cout<<"Linia "<<i<<" are "<<max<<" elemente
nenule"<<endl;
}
}