//Program to find product of two matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A,B,C,m,n,p,q,i,k,j;
cout<<"\n enter the size of first matrix :";
cin>>m>>n;
cout<<"\n enter the size of second matrix :";
cin>>p>>q;
if(n==p)
{
cout<<"\n product of two matrix is possible ";
cout<<"\n enter the elements of first matrix ";
{
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cout<<"\n enter A["<<i<<"]["<<j<<"]";
cin>>A[i][j];
}
}
cout<<"\n enter the elements of second matrix";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\n enter B["<<i<<"]["<<j<<"]";
cin>>B[i][j];
}
}
cout<<"\n the first matrix is :";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
cout<<"\n second matrix is:";
for(i=0;i<p;i++)
{
cout<<"\n ";
for(j=0;j<q;j++)
cout<<B[i][j]<<" ";
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
C[i][j]=0;
}
for(i=0;i<m;i++)
for(j=0;j<q;j++)
for(k=0;k<n;k++)
{
C[i][j]+=A[i][k]*B[k][j];
}
}
cout<<"\n the product of two matrix is :";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
cout<<C[i][j]<<" ";
}
}
else
cout<<"\n multiplication is not possible:";
getch();
}
Program to find the product of two matrices | Learn C++ (Introduction and Tutorials to C++ Programming) Reviewed by SHERE KHOJRAHA on February 13, 2019 Rating: 5