# Write A C++ Program To Multiply Any Two 3 X 3 Matrices.

by Dinesh Thakur Category: Array Pointer and Union

```#include<iostream.h>#include<conio.h>void main( ){           int mat1 , mat2,mat3, i ,j, k, sum;            clrscr( ) ;           cout<<"\nEnter values for first 3 x 3 matrix:\n";           for ( i = 0 ; i <= 2 ; i++ )                {                   for (j = 0 ; j <= 2 ; j++ )                        cin>>mat1 [i][j] ;                }                        cout<<"\n Enter values for second 3 x 3 matrix:\n";                   for ( i = 0 ; i <= 2 ; i++ )                        {                            for ( j = 0 ; j <= 2 ; j++ )                                   cin>>mat2[i][j] ;                        }                       cout<<"\n The first 3 x 3 matrix entered by you is:\n";                            for ( i = 0 ; i <= 2 ; i++ )                                 {                                       for ( j = 0 ; j <= 2 ; j++ )                                              cout<<"\t"<< mat1[i][j] ;                                              cout<<"\n";                                 }                                              cout<<"\n the second 3 x 3 matrix entered :\n";                                       for ( i = 0 ; i <= 2 ; i++ )                                            {                                                for ( j = 0 ; j <= 2 ; j++ )                                                       cout<<"\t"<< mat2[i][j] ;                                                       cout<<"\n";                                            }                                       for ( i = 0 ; i <= 2 ; i++ )                                            {                                                for ( j = 0 ; j <= 2 ; j++ )                                                      {                                                          sum = 0;                                                            for ( k = 0 ; k <=2 ; k++ )                                                                   sum = sum + mat1 [i][k] * mat2[k][j];                                                                   mat3[i][j] = sum ;                                                       }                                             }                                                                   cout<<"\nThe product of the above two matrices is:\n";                                                                   for ( i = 0 ;i<= 2 ; i++ )                                                                        {                                                                             for ( j = 0 ; j <= 2 ; j++ )                                                                                      cout<<"\t"<<mat3[i][j] ;                                                                                      cout<<"\n";                                                                         }                                                                                      cout<<"\n Press any key to exit.";                                                                                      getch( ) ;}
```  Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles