Skip to content

Commit 911c934

Browse files
authored
Merge pull request #1 from JatinBagai/main
Multiply Two Matrices
2 parents 945af9f + add13b2 commit 911c934

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

MultiplyTwoMatrice.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
6+
int r1, c1;
7+
cout << "Enter the order of the first matrix: ";
8+
cin >> r1 >> c1;
9+
int r2, c2;
10+
cout << "Enter the order of the second matrix: ";
11+
cin >> r2 >> c2;
12+
while(c1 != r2){
13+
cout << "Enter order again" << "\n";
14+
cout << "Enter the order of the first matrix: ";
15+
cin >> r1 >> c1;
16+
cout << "Enter the order of the second matrix: ";
17+
cin >> r2 >> c2;
18+
}
19+
int arr1[r1][c1], arr2[r2][c2], arr3[r1][c2];
20+
cout << "Enter the elements of the first matrix: " << "\n";
21+
for(int i=0;i<r1;i++)
22+
{
23+
for(int j=0;j<c1;j++)
24+
{
25+
cin >> arr1[i][j];
26+
}
27+
}
28+
cout << "Enter the elements of the second matrix: " << "\n";
29+
for(int i=0;i<r2;i++)
30+
{
31+
for(int j=0;j<c2;j++)
32+
{
33+
cin >> arr2[i][j];
34+
}
35+
}
36+
for(int i=0;i<r1;i++)
37+
{
38+
for(int j=0;j<c2;j++)
39+
{
40+
arr3[i][j] = 0;
41+
for(int k=0;k<c1;k++)
42+
{
43+
arr3[i][j] += arr1[i][k]*arr2[k][j];
44+
}
45+
}
46+
}
47+
cout << "The resultant matrix is: " << "\n";
48+
for(int i=0;i<r1;i++)
49+
{
50+
for(int j=0;j<c2;j++)
51+
{
52+
cout << arr3[i][j] << " ";
53+
}
54+
cout << "\n";
55+
}
56+
return 0;
57+
}

0 commit comments

Comments
 (0)