Create a program which contain M and N matrices with the order of 2x2 then assign them any value After that multiply both matrices and print the result matrix on console.
Code:
#include <iostream>
using namespace std;
int main()
{
int m[2][2],n[2][2];
cout<<"Assign values to first matrix : "<<endl;
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
cin>>m[i][j];
}
}
cout<<"Assign values to second matrix : "<<endl;
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
cin>>n[i][j];
}
}
int l[2][2]={0};
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
for (int k=0;k<2;k++)
{
l[i][j] += m[i][k] * n[k][j];
}
}
}
cout<<"The matrix after multiplication is given below : "<<endl;
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
cout<<l[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Result:
Comments
Post a Comment