#include<iostream.h>
#include<conio.h>
int lar(int [][10],int);
int sml(int [][10],int);
int main()
{
int a[10][10],largest,smallest;
int size;
cout<<"himanshu singh\n";
cout<<"for 2d array enter size and array";
cin>>size;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
cin>>a[i][j];
for(int t=0;t<size;t++)
{ for(int e=0;e<size;e++)
cout<<" "<<a[t][e];
cout<<"\n";
}
largest = lar(a,size);
cout<<"\n Largest element in this array was= ";
cout<<largest;
cout<<"\n";
smallest = sml(a,size);
cout<<"\n Smallest element in this array was= ";
cout<<smallest;
getch();
return 0;
}
int lar(int a1[][10],int n)
{
int l=a1[0][0];
for(int p=0;p<n;p++)
for(int q=0;q<n;q++)
if(l<a1[p][q])
l=a1[p][q];
return (l);
}
int sml(int a2[][10],int z)
{
int s=a2[0][0];
for(int r=0;r<z;r++)
for(int w=0;w<z;w++)
if(s>a2[r][w])
s=a2[r][w];
return (s);
}
OUTPUT
#include<conio.h>
int lar(int [][10],int);
int sml(int [][10],int);
int main()
{
int a[10][10],largest,smallest;
int size;
cout<<"himanshu singh\n";
cout<<"for 2d array enter size and array";
cin>>size;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
cin>>a[i][j];
for(int t=0;t<size;t++)
{ for(int e=0;e<size;e++)
cout<<" "<<a[t][e];
cout<<"\n";
}
largest = lar(a,size);
cout<<"\n Largest element in this array was= ";
cout<<largest;
cout<<"\n";
smallest = sml(a,size);
cout<<"\n Smallest element in this array was= ";
cout<<smallest;
getch();
return 0;
}
int lar(int a1[][10],int n)
{
int l=a1[0][0];
for(int p=0;p<n;p++)
for(int q=0;q<n;q++)
if(l<a1[p][q])
l=a1[p][q];
return (l);
}
int sml(int a2[][10],int z)
{
int s=a2[0][0];
for(int r=0;r<z;r++)
for(int w=0;w<z;w++)
if(s>a2[r][w])
s=a2[r][w];
return (s);
}
OUTPUT
No comments:
Post a Comment