-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMultiplyTwoMatrice.cpp
57 lines (55 loc) · 1.36 KB
/
MultiplyTwoMatrice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
int main(){
int r1, c1;
cout << "Enter the order of the first matrix: ";
cin >> r1 >> c1;
int r2, c2;
cout << "Enter the order of the second matrix: ";
cin >> r2 >> c2;
while(c1 != r2){
cout << "Enter order again" << "\n";
cout << "Enter the order of the first matrix: ";
cin >> r1 >> c1;
cout << "Enter the order of the second matrix: ";
cin >> r2 >> c2;
}
int arr1[r1][c1], arr2[r2][c2], arr3[r1][c2];
cout << "Enter the elements of the first matrix: " << "\n";
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
cin >> arr1[i][j];
}
}
cout << "Enter the elements of the second matrix: " << "\n";
for(int i=0;i<r2;i++)
{
for(int j=0;j<c2;j++)
{
cin >> arr2[i][j];
}
}
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
arr3[i][j] = 0;
for(int k=0;k<c1;k++)
{
arr3[i][j] += arr1[i][k]*arr2[k][j];
}
}
}
cout << "The resultant matrix is: " << "\n";
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
cout << arr3[i][j] << " ";
}
cout << "\n";
}
return 0;
}