-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplyMatrix.cpp
More file actions
55 lines (52 loc) · 1.02 KB
/
MultiplyMatrix.cpp
File metadata and controls
55 lines (52 loc) · 1.02 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
#include <stdio.h>
int main()
{
unsigned long long int t,i,n,matrix[31][31],result[31][31],j,k,l,c,d,b,x,z,a=0,sum=0;
scanf("%d",&t);
for(x=0;x<31;x++)
{
for(z=0;z<31;z++)
{
matrix[x][z]=0;
result[x][z]=0;
}
}
for (i=0;i<t;i++)
{
scanf("%d",&n);
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
scanf("%d",&matrix[j][k]);
}
}
printf("Case #%d:\n",i+1);
for(c=0;c<n;c++)
{
for(d=0;d<n;d++)
{
for (l=0;l<n;l++)
{
sum += (matrix[c][l]*matrix[l][d])%1000000007;
}
result[c][d] = sum ;
sum = 0;
}
}
for ( int j = 0 ; j < n ; j++ ) {
for ( int k = 0 ; k < n ; k++ ) {
if(a==n)
{
printf("\n");
a=0;
}
printf("%d ",result[j][k]);
result[j][k] = 0;
a++;
}
}
printf("\n");
}
return 0;
}