what is the algorithm for the product of two same size matrices?
Printable View
what is the algorithm for the product of two same size matrices?
heres the program of two 3x3 mat. I dug it up from some unknown hidden corner of my comp. ;)
Code:void mulofmatr(void)
{
int a[3][3],b[3][3],c[3][3],i,j,p,q,x,y,pro,sum;
clrscr();
cout<<"ENTER ELEMENTS OF MATRIX A[3][3] :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"ENTER ELEMENTS OF MATRIX B[3][3] :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>b[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
p=i;
q=0;
x=0;
y=j;
sum=0;
pro=1;
while(q<=2)
{
pro=a[p][q]*b[x][y];
sum=sum+pro;
q=q+1;
x=x+1;
}
c[i][j]=sum;
}
cout<<"\nELEMENTS OF MATRIX C AFTER MULTIPLICATION : ";
for(i=0;i<3;i++)
{
cout<<'\n';
for(j=0;j<3;j++)
{
cout<<c[i][j];
cout<<"\t";
}
}
}