#include<iostream.h>
#include<conio.h>
class Matrix
{
int a[3][3];
public:
void accept()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<endl<<"Enter a value(["<<i+1<<"]["<<j+1<<"]): ";
cin>>a[i][j];
}
}
}
void display()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
}
Matrix operator*(Matrix m)
{
Matrix temp;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
temp.a[i][j]=0;
for(int k=0;k<3;k++)
{
temp.a[i][j]=temp.a[i][j]+a[i][k]*m.a[k][j];
}
}
}
return temp;
}
};//end of class
int main()
{
Matrix m1,m2,m3;
clrscr();
cout<<endl<<"Enter matrix1: ";
m1.accept();
cout<<endl<<"Enter matrix2: ";
m2.accept();
m3=m1*m2;
cout<<endl<<"MATRIX1 is: "<<endl;
m1.display();
cout<<endl<<"MATRIX2 is: "<<endl;
m2.display();
cout<<endl<<"MATRIX3 = MATRIX1 * MATRIX2 is: "<<endl;
m3.display();
getch();
return 0;
}
Post a Comment