Posted By:
21 Jun, 2013 9:08 am PDT

Arrays in C

How to multiply 2 matrices?
Attachment:None


The user has to firstly enter the size of the matrices and for matrix multiplication to occur the size of matrix should be as follows, first (m, n) & second (n, p).

The size of the output matrix would be out (m, p).

The main loop to multiply the matrices would be:

for ( c = 0 ; c < m ; c++ )

 {   

    for ( d = 0 ; d < q ; d++ )       

    {       

        for ( k = 0 ; k < p ; k++ )           

        {           

            sum = sum + first[c][k]*second[k][d];        

        }

        multiply[c][d] = sum;

        Sum = 0;  

    }

}

Please see the video for more details

Was it useful?  



To multiply two matrices the most important thing is that , the number of columns of first matrix and number of rows of second matrix must be same. 

 

if( n != p )

    printf("Matrices with entered orders can't be multiplied with each other.\n");

The main loop for matrix multiplication is 

    for( c =0; c < m ; c++)

    {

      for( d =0; d < q ; d++)

      {

        for( k =0; k < p ; k++)

        {

          sum = sum + first[c][k]*second[k][d];

        }

 

        multiply[c][d]= sum;

        sum =0;

      }

    }

 

have a look at the attached file to understand the problem.

Attachment: matrix.docx

Was it useful?  




Please login to reply to this problem.