#include <iostream.h>
#include <conio.h>
#include <process.h>void main()
{
int mat1[10][10] , mat2[10][10];
int m,n,p,q;
// Input elements (matrix 1 ) ------
cout<< "\n Enter no. of rows for matrix 1:";
cin >> m;
cout<< "\n Enter no. of columns :";
cin >> n;
for(int i = 0; i < m ; i++)
for( int j = 0; j < n ; j++)
{cout<<"\n Enter elements for "<< i+1 << "," << j+1 < <"location :";
cin >> mat1[i][j];
}
// Input elements (matrix 2 ) ------
cout<< "\n Enter no. of rows for matrix 2:";
cin >> p;
cout<< "\n Enter no. of columns :";
cin >> q;
for(i = 0; i < p ; i++)
for(j = 0; j < q ; j++)
{cout<<"\n Enter elements for "<< i+1 << "," << j+1 < <"location :";
cin >> mat2[i][j];
}
// check dimensions
if (( m ! = n ) || (p ! = q) )
{
cout<< "\n Two matrices are unequal . ";
getch ( );
exit (1);
}
//check individual elements
for( i = 0; i < m ; i++)
for( j = 0; j < n; j++)
if(mat1[i][j] ! = mat2[i][j])
{
cout<< "\n Two matrices are unequal . ";
getch ( );
exit (1);
}
cout<< " \n Two matrices are exactly equal . "
//Print the array
cout<<"\n The matrix : \n\n";
for( i = 0; i < m ; i++)
{for( j = 0; j < n ; j++)
cout<< mat1[i][j]<<"\t";
cout<< "\n";
}
getch ( );
}
No comments:
Post a Comment