PROGRAM
//Program to perform multiplication of two matrices
# include <iostream>
using namespace std;
int main()
{
int a[3][3],b[3][3],c[3][3],i,j,k,s;
cout<<"ENTER FIRST MATRIX ROW WISE:\n";
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}
cout<<endl;
}
cout<<"ENTER SECOND MATRIX ROW WISE:\n";
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cout<<"b["<<i<<"]["<<j<<"]=";
cin>>b[i][j];
}
cout<<endl;
}
//Loop For Multiplication
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
for(k=0 ; k<3 ; k++)
{
s = s + (a[i][k] * b[k][j]);
}
c[i][j]=s;
s=0;
}
}
cout<<"\nRESULT\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
OUTPUT
//Program to perform multiplication of two matrices
# include <iostream>
using namespace std;
int main()
{
int a[3][3],b[3][3],c[3][3],i,j,k,s;
cout<<"ENTER FIRST MATRIX ROW WISE:\n";
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}
cout<<endl;
}
cout<<"ENTER SECOND MATRIX ROW WISE:\n";
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cout<<"b["<<i<<"]["<<j<<"]=";
cin>>b[i][j];
}
cout<<endl;
}
//Loop For Multiplication
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
for(k=0 ; k<3 ; k++)
{
s = s + (a[i][k] * b[k][j]);
}
c[i][j]=s;
s=0;
}
}
cout<<"\nRESULT\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
OUTPUT
2 comments
commentsHOGHCOOL
Replythank you for sharing useful post.
Replyc++ programming tutorial
welookups