c++ program to multiply matrices (two dimensional array), this program multiplies two matrices which will be entered by the user. Firstly user will enter the order of a matrix. If the entered orders of two matrix is such that they can't be multiplied then an error message is displayed on the screen.
You have already studied the logic to multiply them in Mathematics.
Matrices are frequently used while doing programming and are used to represent graph data structure, in solving system of linear equations and many more. Lot of research is being done on how to multiply matrices using minimum number of operations. You can also implement it using pointers.
Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[10][10],b[10][10],c[10][10],l,m,n,o,i,j,k;
cout<<"Matrix Multiplication by-Tarun Rawat\n";
again:
cout<<"\nEnter Row & Column Of Matrix A \n";
cin>>l>>m;
cout<<"\nEnter Row & Column Of Matrix B \n";
cin>>n>>o;
if(m==n)
{cout<<"Matrix Can Be Multiply \n";
}
else{ cout<<"Incorrect Matrix For Multiplication \n";
goto again;
}
cout<<"\nEnter Elements Of Matrix A: \n";
for(i=0;i<l;i++)
{ for(j=0;j<m;j++)
{cin>>a[i][j];
}
}
cout<<"\nEnter Elements Of Matrix B: \n";
for(i=0;i<n;i++)
{ for(j=0;j<o;j++)
{cin>>b[i][j];
}
}
for(i=0;i<l;i++)
{for(j=0;j<o;j++)
{c[i][j]=0;
for(k=0;k<m;k++)
{c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
cout<<"\nMultiplication Of Matrix A & B: ";
for(i=0;i<l;i++)
{cout<<"\n";
for(j=0;j<o;j++)
{ cout<<c[i][j]<<" ";
}
}
getch();
}
Welcome to " way2cplusplus.blogspot.in " Objective of this blog is to implement various Computer Science Engineering Lab problems into C++ programming language. These are basically most common Lab Exercise problems based on the curriculum of engineering colleges throughout the Nation. These lab exercises are also relevant to Data structure. Simply C++ programming zone...
good job
ReplyDeletewell done
ReplyDelete