C++ PRACTICAL PROGRAMS
Class 12 Computer Science | ASSEB
Program to find the product of two matrices
#include<iostream>
using namespace std;
int main( )
{
int a[3][3],b[3][3],p[3][3],i,j;
cout<<”Enter the first matrix”;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<”Enter the second matrix”;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cin>>b[i][j];
}
}
for (i=0; i<3;i++)
{
for (j=0; j<3;j++)
{ p[i][j]=a[i][j]*b[i][j]; }
}
cout<<”Product of two matrices is \n”;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cout<<p[i][j]<<” “;
}
cout<<”\n”;
}
return 0;
}
Output
Enter the first matrix3
2
1
2
3
4
4
5
5
Enter the second matrix2
3
4
1
2
3
4
6
7
Product of two matrices is
6 6 4
2 6 12
16 30 35