"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, February 18, 2010

Product of Matrices


#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

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.