how to search for the greatest number in an 2d array in c ++ ?
Answers
Answered by
1
int main()
{
int a[5][5],large=1,n,m,i,j;
cout<<"Enter the number of rows and columns:";
cin>>m>>n;
cout<<"Enter array:\n";
for(i=0;i<m;i++)
for(j=0;j<n;++j)
cin>>a[i][j];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>large)
large=a[i][j];
}
cout<<"\nLargest number from the array is :"<<large;
return 0;
}
{
int a[5][5],large=1,n,m,i,j;
cout<<"Enter the number of rows and columns:";
cin>>m>>n;
cout<<"Enter array:\n";
for(i=0;i<m;i++)
for(j=0;j<n;++j)
cin>>a[i][j];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>large)
large=a[i][j];
}
cout<<"\nLargest number from the array is :"<<large;
return 0;
}
Similar questions