-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4(b).cpp
More file actions
46 lines (38 loc) · 1.09 KB
/
Copy pathQ4(b).cpp
File metadata and controls
46 lines (38 loc) · 1.09 KB
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
#include <iostream>
using namespace std;
int main() {
int r1, c1, r2, c2;
cout << "Enter rows and cols of first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and cols of second matrix: ";
cin >> r2 >> c2;
if (c1 != r2) {
cout << "Matrix multiplication not possible!" << endl;
return 0;
}
int A[10][10], B[10][10], C[10][10] = {0};
cout << "Enter first matrix:\n";
for (int i = 0; i < r1; i++)
for (int j = 0; j < c1; j++)
cin >> A[i][j];
cout << "Enter second matrix:\n";
for (int i = 0; i < r2; i++)
for (int j = 0; j < c2; j++)
cin >> B[i][j];
// Multiplication
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
for (int k = 0; k < c1; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
cout << "Resultant matrix:\n";
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
cout << C[i][j] << " ";
}
cout << endl;
}
return 0;
}