//Strassen multiplication algorithm
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j;
int m1,m2,m3,m4,m5,m6,m7;
clrscr();
printf("enter elements in matrix1 \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
}
m1=(a[1][1]+a[2][2])*(b[1][1]+b[2][2]);
m2=(a[2][1]+a[2][2])*(b[1][1]);
m3=(a[1][1])*(b[1][2]-b[2][2]);
m4=(a[2][2])*(b[2][1]-b[1][1]);
m5=(a[1][1]+a[1][2])*(b[2][2]);
m6=(a[2][1]-a[1][1])*(b[1][1]+b[1][2]);
m7=(a[1][2]-a[2][2])*(b[2][1]+b[2][2]);
c[1][1]=m1+m4-m5+m7;
c[1][2]=m3+m5;
c[2][1]=m2+m4;
c[2][2]=m1+m3-m2+m6;
printf("matrix1 is \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d \t",a[i][j]);
}
printf("\n");
}
printf("\nmatrix2 is \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d \t",b[i][j]);
}
printf("\n");
}
printf("\nfinal matrix\n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%d \t",c[i][j]);
}
printf("\n");
}
getch();
}
//program written by Mars.
No comments:
Post a Comment
You are welcome, your comment helps me to make this blog more better.