-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strassen_Matrix_Multiplication.cpp
65 lines (61 loc) · 1.13 KB
/
Strassen_Matrix_Multiplication.cpp
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
62
63
64
65
#include<stdio.h>
int main()
{
int matA[2][2],matB[2][2],matC[2][2];
int i,j,p,q,r,s,t,u,v;
printf("Enter the values of matrix A\n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
scanf("%d",&matA[i][j]);
}
}
printf("Enter the values of matrix B\n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
scanf("%d",&matB[i][j]);
}
}
p=(matA[1][1]+matA[2][2])*(matB[1][1]+matB[2][2]);
q=(matA[2][1]+matA[2][2])*matB[1][1];
r=matA[1][1]*(matB[1][2]-matB[2][2]);
s=matA[2][2]*(matB[2][1]-matB[1][1]);
t=(matA[1][1]+matA[1][2])*matB[2][2];
u=(matA[2][1]-matA[1][1])*(matB[1][1]+matB[1][2]);
v=(matA[1][2]-matA[2][2])*(matB[2][1]+matB[2][2]);
matC[1][1]=p+s-t+v;
matC[1][2]=r+t;
matC[2][1]=q+s;
matC[2][2]=p+r-q+u;
printf("The A matrix is \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d\t",matA[i][j]);
}
printf("\n");
}
printf("The B matrix is \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d\t",matB[i][j]);
}
printf("\n");
}
printf("The multiplication matrix is \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d\t",matC[i][j]);
}
printf("\n");
}
return 0;
}