To Perform Multiplication of two Matrices

Program:


    #include<iostream.h>
    #include<conio.h>
    #define size 5
class array { private: int I,j,k,x[size][size],y[size][size],z[size][size]; public: void enter(int x[size][size],int,int); void display(int x[size][size],int,int); void mat_multiply(int x[size][size],int y[size][size],int z[size][size],int,int,int); }; void array::enter(int x[size][size],int row,int colm) { for(I=0;I<row;I++) { for(j=0;j<colm;j++) cin>>x[I][j]; } } void array::display(int x[size][size],int row,int colm) { for(I=0;I<row;I++) { for(j=0;j<colm;j++) cout<<x[I][j]<<'\t'; cout<<endl; } } void array::mat_multiply(int x[size][size],int y[size][size],int z[size][size],int row1,int colm1,int colm2) { for(I=0;I<row1;I++) { for(j=0;j<colm2;j++) { z[I][j]=0; for(k=0;k<colm1;k++) z[I][j]+=x[I][k]*y[k][j]; } } } void main() { array obj; int a[size][size],b[size][size],c[size][size],row1,colm1,row2,colm2; clrscr(); cout<<"\nEnter the order of First matrix < "<<size<<" * "<<size<<"\n"; cin>>row1>>colm1; cout<<"\nEnter the order of Second matrix < "<<size<<" * "<<size<<"\n"; cin>>row2>>colm2; if(colm1==row2) { cout<<"\nEnter the first matrix of order "<<row1<<" * "<<colm1<<endl; obj.enter(a,row1,colm1); cout<<"\nEnter the second matrix of order "<<row2<<" * "<<colm2<<endl; obj.enter(b,row2,colm2); clrscr(); cout<<"\nFirst matrix is \n\n"; obj.display(a,row1,colm1); cout<<"\nSecond matrix is \n\n"; obj.display(b,row2,colm2); obj.mat_multiply(a,b,c,row1,colm1,colm2); cout<<"\nMultiplication of two matrices is\n\n"; obj.display(c,row1,colm1); } else cout<<"Matrix multiplication is not possible"; getch(); }
Powered by nasrullah.in - TechnoNasr 2003-2020.
Designed & Developed by Mohamed Nasrullah.M