WAP to find small no in matrix
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5][5],n,m,i,j,small;
cout<<"\n enter size of rows :";
cin>>n;
cout<<"\n enter size of collumns :";
cin>>m;
cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n 2d array \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
}
small=a[1][1];
for(i=2;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(small>a[i][j])
{
small=a[i][j];
}
}
}
cout<<"\n The smallest element is "<<small;
getch();
clrscr();
}
No comments:
Post a Comment