Write a C++ program to multiply array X and Y of order NxL and LxM.
Note: We consider NxL = 3x3 and LxM = 3X3
Note: We consider NxL = 3x3 and LxM = 3X3
Program Code:
#include<iostream>
using namespace std;
int main()
{
int X[3][3], Y[3][3], MULTI[3][3];
int sum=0, i, j, k;
cout<<"Enter element of first matrix : ";
cout<<endl;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>X[i][j];
}
}
cout<<"Enter element of second matrix : ";
cout<<endl;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>Y[i][j];
}
}
// Multiplying two matrices........
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sum=0;
for(k=0; k<3; k++)
{
sum = sum + X[i][k] * Y[k][j];
}
MULTI[i][j] = sum;
}
}
cout<<"Multiplication of two Matrices X and Y is : ";
cout<<endl;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cout<<MULTI[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter element of first matrix :
1 2 3 4 5 6 7 8 9
Enter element of second matrix :
9 8 7 6 5 4 3 2 1
Multiplication of two Matrices X and Y is :
30 24 18
84 69 54
138 114 90
Thanks
Mukesh Rajput
Post A Comment:
0 comments: