Here is a C++ program to find smallest and largest element of matrix
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int a[10][10],row,col,min,max;
cout<<"Enter row and column of matrix (max 10*10): ";
cin>>row>>col;
cout<<"Enter matrix a1 : "<<endl;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>a[i][j];
max=min=a[0][0];
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
{
if(min>a[i][j])
min=a[i][j];
if(max<a[i][j])
max=a[i][j];
}
cout<<"Smallest element of matrix : "<<min;
cout<<"\nLargest element of matrix : "<<max;
return 0;
}
using namespace std;
int main()
{
int a[10][10],row,col,min,max;
cout<<"Enter row and column of matrix (max 10*10): ";
cin>>row>>col;
cout<<"Enter matrix a1 : "<<endl;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>a[i][j];
max=min=a[0][0];
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
{
if(min>a[i][j])
min=a[i][j];
if(max<a[i][j])
max=a[i][j];
}
cout<<"Smallest element of matrix : "<<min;
cout<<"\nLargest element of matrix : "<<max;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment