WAP for multiplication of matrix
#include<iostream.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],n,m,i,j,k;
cout<<"\n enter size of rows :";
cin>>n;
cout<<"\n enter size of collumns :";
cin>>m;
cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n first matrix \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n\n";
}
cout<<"\n enter same size of rows :";
cin>>n;
cout<<"\n enter same size of collumns :";
cin>>m;
cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>b[i][j];
}
}
cout<<"\n second matrix \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<b[i][j];
}
cout<<"\n\n";
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
c[i][j]=0;
for(k=1;k<=n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
cout<<"\n multiplication of matrix is \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<c[i][j];
}
cout<<"\n\n";
}
getch();
clrscr();
}
No comments:
Post a Comment