#include <stdio.h>
#include <stdlib.h>
void Strassen(int mx1[][2],int mx2[][2],int n)
{
int a,b,c,d,e,f,g,h,P1,P2,P3,P4,P5,P6,P7,Q1,Q2,Q3,Q4,R[2][2],i,j;
a = mx1[0][0] ;
b = mx1[0][1] ;
c = mx1[1][0] ;
d = mx1[1][1] ;
e = mx2[0][0] ;
f = mx2[0][1] ;
g = mx2[1][0] ;
h = mx2[1][1] ;
P1 = a *( f - h ) ;
P2 = ( a + b ) * h ;
P3 = ( c + d ) * e ;
P4 = d * ( g - e ) ;
P5 = ( a + d ) * ( e + h ) ;
P6 = ( b - d ) * ( g + h ) ;
P7 = ( a - c ) * ( e + f ) ;
Q1 = P5 + P4 + P6 - P2 ;
Q2 = P1 + P2 ;
Q3 = P3 + P4 ;
Q4 = P1 + P5 - P3 - P7 ;
R[0][0] = Q1; R[0][1] = Q2; R[1][0] = Q3; R[1][1] = Q4;
printf("\n");
for( i = 0 ; i < n ; i++ )
for( j = 0 ; j < n ; j++ )
printf(" %d ",R[i][j]);
}
int main()
{
int n,MX1[2][2],MX2[2][2],i,j;
printf("\n\t\tSTRASSEN'S ALGORITHM\n\nEnter the size of the matrix: ");
scanf("%d",&n);
printf("Enter the elements of the first matrix: ");
for( i = 0 ; i < n ; i++ )
for( j = 0 ; j < n ; j++ )
scanf("%d",&MX1[i][j]);
printf("Enter the elements of the second matrix");
for( i = 0 ; i < n ; i++ )
for( j = 0 ; j < n ; j++ )
scanf("%d",&MX2[i][j]);
printf("\nThe resultant matrix is :");
Strassen(MX1,MX2,n);
return 0;
}