C++ Program to perform multiplication of two matrices [DEVCPP/GCC]

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

C++ Program to perform multiplication of two matrices with output

Share this

Related Posts

2 comments

comments

FIND US ON FACEBOOK!