mastery 26

 

A matrix is pretty much like an array, only that it has two dimensions using nested loops. Just like C++ Home sais “A matrix is, by definition, a rectangular array of numeric or algebraic quantities which are subject to mathematical operations. “(C++ Home, 2001)

Matrices are used to make operations that take a lot of time or are often really complicated to do manualy. One matrix can contain many operations and information that can be used later in other matrix or in vectors and arrays. Some of the operations that can be used in matrixes are:

addition

multiplication

inverse calculation   (C++ Home, 2001)

Here is an example of a product of numbers:

<iostream>

 

using namespace std;

int main(){

    const int row=2,col=2;

cout<<“Size of Matrices : “<<row<<” X “<<col<<endl;

cout<<“Enter Value For FirstMatrix Matrix:”<<endl;

    int firstMatrix[row][col];

    int secondMatrix[row][col];

    int resultantMatrix[row][col], var;

int i,j;

    for( i=0;i<row;i++){

        cout<<“Enter value for row number: “<<i+1<<endl;

        for( j=0;j<col;j++){

            cin>>firstMatrix[i][j];

        }

    }

cout<<” Enter Value For SecondMatrix Matrix:”<<endl;

    for( i=0;i<row;i++){

        cout<<“Enter value for row number: “<<i+1<<endl;

        for( j=0;j<col;j++){

            cin>>secondMatrix[i][j];

        }

    }

var=0;

        for( i=0;i<row;i++){

            for( j=0;j<col;j++){

                for(int k=0;k<row;k++){

                   var=var+(firstMatrix[i][k]*secondMatrix[k][j]);

                   cout<<var<<endl;

                    }

                 resultantMatrix[i][j]=var;

                 var=0;

            }

        }

cout<<“nnttResultant Matrix:”<<endl;

    for( i=0;i<row;i++){

        cout<< endl;

        for( j=0;j<col;j++){

            cout<<“tt”<<resultantMatrix[i][j]<<”    “;

        }

    }

return 0;

 

}

CC BY 4.0 mastery 26 by carlos green is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.