what is the algorithm for the product of two same size matrices?
This is a discussion on matrix multiplication within the C++ Programming forums, part of the General Programming Boards category; what is the algorithm for the product of two same size matrices?...
what is the algorithm for the product of two same size matrices?
once a kohatian,always a kohatian!
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"; } } }
Last edited by ihsir; 04-18-2002 at 08:33 AM.
-