Multiply 2 matrices

PROBLEM :

For 2 given matrix of size 3*3 multiply them and print the matrix.

Input:
The first line contains an integer 'T' denoting the total number of test cases.
In each test cases, it consists of six lines and each line has three integers. First three line denoted the first matrix and then next three line denotes the second matrix.


Output:
Print three lines and in each line three integers which is resultant matrix after multiplication of 2 matrices.


Constraints:
1<=T<=30
1<=Number<=100


Example:
Input:
1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

Output:
3 3 3
3 3 3
3 3 3
     
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
int main()
 {
int t ,i,j,k,sum ;
int a[100][100],b[100][100],c[100][100];
cin>>t ;
while(t--)
{
   for(i=0;i<3;i++)
       for(j=0;j<3;j++)
           cin>>a[i][j] ;
         
   for(i=0;i<3;i++)
       for(j=0;j<3;j++)
           cin>>b[i][j] ;
         
   for(i=0;i<3;i++)
   {
       for(j=0;j<3;j++)
       {
           sum=0 ;
           for(k=0;k<3;k++)
               sum=sum+a[i][k]*b[k][j] ;
           c[i][j]=sum ;
       }
   }
 
   for(i=0;i<3;i++)
   {
       for(j=0;j<3;j++)
           cout<<c[i][j]<<" " ;
       cout<<endl ;
   }
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )