-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixMult.cpp
More file actions
62 lines (56 loc) · 1.75 KB
/
Copy pathmatrixMult.cpp
File metadata and controls
62 lines (56 loc) · 1.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
using namespace std;
#define ll long long
ll matrix[10][10] = {
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0}
};
void mMult(ll A[][10], ll B[][10], ll res[][10]) {
// matrix multiplication algorithm
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
res[i][j] = 0;
for (int k = 0; k < 10; k++)
res[i][j] += A[i][k] * B[k][j];
}
}
}
void copy(ll src[][10], ll dest[][10]) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++)
dest[i][j] = src[i][j];
}
}
int main(int argc, char **argv) {
ll a[10][10], res[10][10];
ll prev[10][10];
copy(matrix, a);
copy(a, prev);
for (ll m = 0; m < 1000000000000; m++) {
// cout << m << "round\n";
mMult(prev, matrix, res);
// for (int i = 0; i < 10; i++) {
// for (int j = 0; j < 10; j++) {
// cout << res[i][j] << " ";
// }
// cout << "\n";
// }
// cout << "\n\n";
copy(res, prev);
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
cout << res[i][j] << "\t\t";
}
cout << "\n\n";
}
return 0;
}