#include<iostream.h>
#include<conio.h>
class met
{
int
a[10][10],b[10][10],c[10][10],c1,c2,r1,r2,i,j,k;
public:
void read()
{
cout<<"enter the order of
the first matrix :";
cin>>r1>>c1;
cout<<"enter the order of
the second matrix :";
cin>>r2>>c2;
if(c1!=r2)
cout<<"multiplication is
not possible";
else
{
cout<<"enter the elements
in the first matrix :";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>a[i][j];
}
cout<<"enter the elements
in second matrix :";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cin>>b[i][j];
}
}
}
public:void mul()
{
cout<<"matrix after
multiplication :\n";
for(i=0;i<r1;i++)
{
cout<<"\n";
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout<<c[i][j]<<"\t";
}
}
}
};
void main()
{
clrscr();
met ob;
ob.read();
ob.mul();
getch();
}
OUTPUT
enter the order
of the first matrix :2 2
enter the order
of the second matrix :2 2
enter the
elements in the first matrix :
1
2
3
4
enter the
elements in second matrix :
1
2
3
4
matrix after
multiplication :
7 10
15 22
0 comments:
Post a Comment