// MATRIX MULTIPLICATION Using Class
#include<iostream>
using namespace std;
class matmul
{
public:
int a[10][10],b[10][10],c[10][10],i,j,k,r1,r2,c1,c2;
void input();
void display();
};
void matmul :: input()
{
cout<<"\n MATRIX MULTIPLICATION "<<endl;
cout<<"\n Size Of First Marix Row : ";
cin>>r1;
cout<<r1;
cout<<"\n Size Of First Marix Column : ";
cin>>c1;
cout<<c1;
cout<<"\n Size Of Second Marix Row : ";
cin>>r2;
cout<<r2;
cout<<"\n Size Of Second Marix Coloumn : ";
cin>>c2;
cout<<c2;
}
void matmul :: display()
{
if(c1==r2)
{
cout<<"\n\n First Matrix Elements : ";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<"\n\n Second Matrix Elements : ";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cin>>b[i][j];
}
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<b[i][j]<<",";
}
}
cout<<"\n\n First Matrix : "<<endl;
for(i=0;i<r1;i++)
{
cout<<"\n\t";
for(j=0;j<c1;j++)
{
cout<<"\t"<<a[i][j];
}
}
cout<<"\n\n Second Matrix : "<<endl;
for(i=0;i<r2;i++)
{
cout<<"\n\t";
for(j=0;j<c2;j++)
{
cout<<"\t"<<b[i][j];
}
}
cout<<"\n\n Matrix Multiplication ; ( A*B )"<<endl;
for(i=0;i<r1;i++)
{
cout<<"\n\t";
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout<<"\t"<<c[i][j];
}
}
cout<<endl;
}
else
{
cout<<"\n\n Can't Be Matrix Multiplication."<<endl;
}
}
int main()
{
matmul a;
a.input();
a.display();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: