#include <iostream.h>
#include <conio.h>
#include<process.h>void main()
{
clrscr();
int A[10][10] , B[10][10] , P[10][10] , i, j, k, m, n, p, q;
cout<< "\n Enter the rows & column of Matrix A :;
cin>> m>> n;
cout<< "\n Enter the rows & column of Matrix B :;
cin>> p>> q;
if(n ! = p)
{
cout<< "\n The Matrix Multiplication is impossible .";
getch();
exit(1);
}
cout<< " \ n Enter the elements for Matrix A :";
for(i = 0; i< m ; i++)
for(j = 0 ; j< n ; j++)
cin >> A[i][j];
cout<< " \ n Enter the elements for Matrix B :";
for(i = 0; i< p ; i++)
for(j = 0 ; j< q ; j++)
cin >> B[i][j];
/* ......Product ...... */
for(i = 0; i< m ; i++)
for(j = 0 ; j< q ; j++)
{
P[i][j] = 0;
for(k = 0; k< n ; k++)
P[i][j] = P[i][j] + A[i][k] * B[k][j];
}
cout<< "\n Matrix A : \n ";
for( i =0; i< m ; i++)
{ for(j = 0; j< n ; j++)
cout<< A[i][j];
cout<< endl;
}
cout<< "\n Matrix B: \n ";
for( i =0; i< p ; i++)
{ for(j = 0; j< q ; j++)
cout<< B[i][j];
cout<< endl;
}
cout<< "\n Product AXB : \n ";
for( i =0; i< m ; i++)
{ for(j = 0; j< q ; j++)
cout<< P[i][j];
cout<< endl;
}
getch();
}
No comments:
Post a Comment