矩阵相乘(c)


/*
  矩阵相乘
*/
#include 
" stdio.h "
#include 
" conio.h "

#define  row 2
#define  col 3

main()
{

    
int  c[row][row] = { 0 };
    
int  a[row][col] = {
                        {
1 , 2 , 3 },
                        {
4 , 5 , 6 }
                    };
    
int  b[col][row] = {
                        {
1 , 2 },
                        {
3 , 4 },
                        {
5 , 6 }
                    };
    
    
int  i,j,k;

    
for (i = 0 ;i < row;i ++ )
    {
       
for (j = 0 ;j < row;j ++ )
       {
           c[i][j]
= 0 ;

           
for (k = 0 ;k < col;k ++ )
           {
               c[i][j]
+= a[i][k] * b[k][j];
           }

       }
    }

    output(a,row,col);
    output(b,col,row);
    output(c,row,row);
    
    getch();
}


output(
int   * arr, int  _row, int  _col)
{
    
int  i = 0 ;
    
while (i < _row * _col)
    {
        
if (i % _col == 0 )printf( " \n " );
        printf(
" %d  " , * (arr + i));

        i
++ ;
    }
    printf(
" \n==================\n " );
}

你可能感兴趣的:(矩阵)