-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmatrix_multiply.cpp
More file actions
39 lines (38 loc) · 1022 Bytes
/
matrix_multiply.cpp
File metadata and controls
39 lines (38 loc) · 1022 Bytes
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
#include <iostream>
using namespace std;
int main() {
int first_matrix[10][10], second_matrix[10][10], result_matrix[10][10], row, column, i, j, k;
cout << "enter the number of row = ";
cin >> row;
cout << "enter the number of column = ";
cin >> column;
cout << "enter the first matrix element =\n";
for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
cin >> first_matrix[i][j];
}
}
cout << "enter the second matrix element = \n";
for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
cin >> second_matrix[i][j];
}
}
cout << "multiply of the matrix = \n";
for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
result_matrix[i][j] = 0;
for (k = 0; k < column; k++) {
result_matrix[i][j] += first_matrix[i][k] * second_matrix[k][j];
}
}
}
//for printing result
for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
cout << result_matrix[i][j] << " ";
}
cout << "\n";
}
return 0;
}