#include<iostream.h>
#include<conio.h>
class strassen
{
int i,j,m,n,p,q,r,s,t,u,v;
int a[10][10],b[10][10],c[10][10];
public:
void get();
void calc();
void display();
};
void strassen::get()
{
cout<<"Enter the Matrix: \n";
cout<<"\nEnter the no. of rows: ";
cin>>m;
cout<<"Enter no. of columns: ";
cin>>n;
cout<<"\n Enter the values: \n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter B Matrix: \n";
cout<<"Enter no. of rows: ";
cin>>m;
cout<<"Enter no. of columns: ";
cin>>n;
cout<<"\n Enter the values: \n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
}
void strassen::calc()
{
p=(a[0][0]+a[1][1])*(b[0][0]+b[1][1]);
q=(a[1][0]+a[1][1])*b[0][0];
r=a[0][0]*(b[0][1]-b[1][1]);
s=a[1][1]*(b[1][0]-b[0][0]);
t=(a[0][0]+a[0][1])*b[1][1];
u=(a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
v=(a[0][1]-a[1][1])*(b[1][0]+b[1][1]);
c[0][0]=p+s-t+v;
c[0][1]=r+t;
c[1][0]=q+s;
c[1][1]=p+r-q+u;
}
void strassen::display()
{
cout<<"\nResulatant matrix: \n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t"<<c[i][j]<<"\t";
}
cout<<endl;
}
}
void main()
{
strassen t;
clrscr();
t.get();
t.calc();
t.display();
getch();
}
Comments
Post a Comment