#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],big1,big2,n,m,i,j;
cout<<"\n Enter no of rows and columns : ";
cin>>m>>n;
cout<<"\n Enter elements \n ";
for(i=0;i<m;i++)
for(j=0;j<n;++j)
cin>>a[i][j];
big1=a[0][0];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>big1)
big1=a[i][j];
}
big2=a[0][0];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>big2 && a[i][j]<big1)
big2=a[i][j];
}
cout<<"\n\n Largest number is : "<<big1;
cout<<"\n Second largest number is : "<<big2;
getch();
}
Output

#include<conio.h>
void main()
{
clrscr();
int a[5][5],big1,big2,n,m,i,j;
cout<<"\n Enter no of rows and columns : ";
cin>>m>>n;
cout<<"\n Enter elements \n ";
for(i=0;i<m;i++)
for(j=0;j<n;++j)
cin>>a[i][j];
big1=a[0][0];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>big1)
big1=a[i][j];
}
big2=a[0][0];
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
if(a[i][j]>big2 && a[i][j]<big1)
big2=a[i][j];
}
cout<<"\n\n Largest number is : "<<big1;
cout<<"\n Second largest number is : "<<big2;
getch();
}
Output
No comments:
Post a Comment