Tuesday, 9 April 2013

Multiplication of 3 x 3 matrices in c++




#include <iostream>
using namespace std;
void main()
{
                    
int arra[3][3];
int arra1[3][3];
int arra3[3][3]={{0,0,0,},{0,0,0}};
cout<<"Fill matrix 'A'"<<endl;
    
for(int i=0;i<3;i++)
{
    
    for(int j=0;j<3;j++)

    {
    cout<<"  insert the values=";
    cin>>arra[i][j];
     
    }
}
cout<<"Fill matrix 'B'"<<endl;
for(int i=0;i<3;i++)
{
    for(int j=0;j<3;j++)
    {
    cout<<"  insert the values=";
    cin>>arra1[i][j];
   
    }

}
system("cls");
cout<<" first  display Matric"<<endl;
cout<<"=============================\n";


for(int i=0;i<3;i++)
{
    for(int j=0;j<3;j++)
    {
    cout<<arra[i][j]<<"\t";
    }
    cout<<endl;
}
cout<<endl;
cout<<" secind display Matric"<<endl;
cout<<"============================\n";

for(int i=0;i<3;i++)
{
    for(int j=0;j<3;j++)

    {
    cout<<arra1[i][j]<<"\t";
    }
    cout<<endl;
}

cout<<endl<<endl;
cout<<"total multiplication "<<endl;
cout<<"==========================\n";

for(int i=0;i<3;i++)
{

    for( int j=0;j<3;j++)
    {

    for( int k=0;k<3;k++)

    {
        arra3[i][j]=arra3[i][j]+(arra[j][k]*arra1[k][j]);
    }
            cout<<arra3[i][j];
            cout<<"\t"; 
    }
    cout<<endl;
   
   }
}

only source code




c++ two dimensional array

0 comments:

Post a Comment