forked from TheAlgorithms/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStrassen Matrix Multiplication.cpp
More file actions
60 lines (50 loc) · 942 Bytes
/
Strassen Matrix Multiplication.cpp
File metadata and controls
60 lines (50 loc) · 942 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;
Multiply(int A[][], int B[][], int n)
{
if (n==2)
{
int p1= (a[0][0] + a[1][1])*(b[0][0]+b[1][1]);
int p2= (a[1][0]+a[1][1])*b[0][0];
int p3= a[0][0]*(b[0][1]-b[1][1]);
int p4= a[1][1]*(b[1][0]-b[0][0]);
int p5= (a[0][0]+a[0][1])*b[1][1];
int p6= (a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
int p7= (a[0][1]-a[1][1])*(b[1][0]+b[1][1]);
int c[n][n];
c[0][0]=p1+p4-p5+p7;
c[0][1]=p3+p5;
c[1][0]=p2+p4;
c[1][1]=p1-p2+p3+p6;
return c[][];
}
else
{
}
}
int main()
{
int p,q,r,s;
cout<<"Enter the dimensions of Matrices";
cin>>n;
int A[n][n],;
int B[n][n],;
cout<<"Enter the elements of Matrix A";
for (int i = 0; i < n; i++)
{
for (int j = 0; j <n ; j++)
{
cin>>A[i][j];
}
}
cout<<"Enter the elements of Matrix B";
for (int i = 0; i < n; i++)
{
for (int j = 0; j <n ; j++)
{
cin>>B[i][j];
}
}
Multiply(A, B, n);
return 0;
}