PROGRAM FOR STRASSEN'S MATRIX MULTIPLICATION


#include<iostream.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j;
int p1,p2,p3,p4,p5,p6,p7;
clrscr();
cout<<"enter the first matrix";
for(i=1;i<=2;i++)
for(j=1;j<=2;j++)
cin>>a[i][j];
cout<<"enter the second matrix";
for(i=1;i<=2;i++)
for(j=1;j<=2;j++)
cin>>b[i][j];
p1=a[1][1]*(b[1][2]-b[2][2]);
p2=(a[1][1]+a[1][2])*b[2][2];
p3=(a[2][1]+a[2][2])*b[1][1];

p4=a[2][2]*(b[2][1]-b[1][1]);
p5=(a[1][1]+a[2][2])*(b[1][1]+b[2][2]) ;
p6=(a[1][2]-a[2][2])*(b[2][1]+b[2][2]) ;
p7=(a[1][1]-a[2][1])*(b[1][1]+b[1][2]) ;
c[1][1]=p5+p4-p2+p6;
c[1][2]=p1+p2;
c[2][1]=p3+p4;
c[2][2]=p5+p1-p3-p7;
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<c[i][j]<<" ";
}
cout<<"\n" ;
}
getch();
}

Comments

  1. plz give the generalized form

    ReplyDelete
  2. Your array indices should start at 0, not 1. You're writing and reading unallocated memory with this program.

    ReplyDelete
  3. MY FRIEND THAT DOESN'T MAKE ANY SENSE ONLY THE LOGICS SHOULD BE CLEAR MEANS TO SAY YA YOU CAN CHANGE TO 0 ITS NOT VERY TRICKY.

    ReplyDelete
  4. if i want create matrix 4x4??? can help me??

    ReplyDelete
  5. do it for 4*4 matrix.2d is not a problem

    ReplyDelete

Post a Comment

Popular posts from this blog

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)