10 Mar 2013

Multiply Matrix

/*

program to multiply two matrices...

*/

#include<iostream.h>
#include<conio.h>
 

void main()
{
 

clrscr();
int x[50][50],y[50][50],z[50][50],i,j,k,a,b,c,d,e,f,g,h;
 

cout<<"Enter the rows and columns for first matrix:"<<endl;
cin>>i>>j;
cout<<"Enter the rows and columns for second matrix:"<<endl;
cin>>k>>a;
cout<<"Enter the elements of the first matrix:"<<endl;
for(b=0;b<i;b++)
for(c=0;c<j;c++)
 {
  cin>>x[b][c];
 }
cout<<"Enter the elements of the second matrix :"<<endl;
for(b=0;b<k;b++)
for(c=0;c<a;c++)
 {
  cin>>y[b][c];
 }
cout<<endl<<endl<<"The corresponding first matrix is:"<<endl;
for(b=0;b<i;b++)
 {
  cout<<endl;
  for(c=0;c<j;c++)
   {
    cout<<x[b][c]<<'\t';
   }
 }
cout<<endl<<endl<<"The corresponding second matrix is:"<<endl;
for(b=0;b<k;b++)
 {
  cout<<endl;
  for(c=0;c<a;c++)
   {
    cout<<y[b][c]<<'\t';
   }
 }
cout<<endl<<endl<<"The product matrix is:"<<endl;
for(b=0;b<i;b++)
 {
  cout<<endl;
  for(c=0;c<a;c++)
   {
    z[b][c]=0;
    for(h=0;h<j;h++)
     {
      z[b][c]+=x[b][h]*y[h][c];
      cout<<z[b][c]<<'\t';
     }
   }
 }


getch();
}

Categories: , , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger