u

Thursday 13 September 2012

C++ Program to create a 3 by 3 array and extract the maximum and the maximum alongwith the original matrix

C++ Program to create a 3 by 3 array and extract the maximum and the maximum alongwith the original matrix

#include<iostream.h>
#include<conio.h>
main()
{
int i,j,a[3][3],max,min;
//Creation of matrix A[3][3]
cout<<"Enter elements of array A"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
max = a[0][0];
min = a[0][0];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if (a[i][j]>max)
max = a[i][j];
if (a[i][j]<min)
min = a[i][j];
}
}
//printing of the original matrix
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<"The maximum element is "<<max;
cout<<endl<<"The minimum element is "<<min;
getch();
return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More