Matrix Multiplication in C

Source code :

#include <stdio.h>
 
int main() {
    
   int c[3][3],i,j,k;
   int sum=0;
 
   int a[3][3] = {
       {1,2,3},
       {1,2,3},
       {1,2,3}
   };
   int b[3][3] = {
       {1,2,3},
       {1,2,3},
       {1,2,3}
   };
   
    printf("The First Matrix is: \n");
    for (i=0;i<3;i++) {
        for (j=0;j<3;j++) {
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
 
    printf("The Second Matrix is : \n");
    for (i=0;i<3;i++) {
        for (j=0;j<3;j++) {
            printf("%d ",b[i][j]);
        }
        printf("\n");
    }
   
    for (i=0;i<3;i++) {
        for (j=0;j<3;j++) {
            for (k=0;k<=2;k++) {
                sum+=a[i][k]*b[k][j];
            }
            c[i][j]=sum;
        }
    }
 
    printf("\nMultiplication Of Two Matrices : \n");
    for (i=0;i<3;i++) {
        for (j=0;j<3;j++) {
            printf("%d ",c[i][j]);
        }
        printf("\n");
    }
 
   return 0;
}

Output :

The First Matrix is:
1 2 3
1 2 3
1 2 3
The Second Matrix is :
1 2 3
1 2 3
1 2 3

Multiplication Of Two Matrices :
6 18 36
42 54 72
78 90 108 

Output :


                

Comments :