-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix multiplication.cpp
More file actions
39 lines (38 loc) · 973 Bytes
/
matrix multiplication.cpp
File metadata and controls
39 lines (38 loc) · 973 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<stdio.h>
#include<string.h>
#define N 64
int a[N][N], b[N][N], res[N][N];
int main()
{
int task;
scanf("%d", &task);
while(task--)
{
int n, i, j, k;
scanf("%d", &n);
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
scanf("%d",&a[i][j]);
}
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
scanf("%d",&b[i][j]);
}
memset(res, 0, sizeof(res));
for(k = 1; k <= n; k++) //be cautious about the order of three loops, memorary, operating system
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
res[i][j] += a[i][k] * b[k][j];
}
for(i = 1; i <= n; i++)
{
for(j = 1; j < n; j++)
printf("%d ", res[i][j]);
printf("%d\n", res[i][n]);
}
}
return 0;
}