Multiply Two Matrices C Program

By | December 15, 2015

C Program To Multiply Two Matrices (3 Dimensional)

Learn How To Multiply Two Matrices in C Programming Language. It is important that we should know about How A For Loop Works before getting further with the C Program Code. This C Program Multiplies Two 3-Dimensional Matrix (Array of Integers) using For Loop.

Note: This Matrix Multiplication C Program is developed in Linux Ubuntu Operating System and compiled with GCC Compiler.

Also Read: C Program To Calculate Sum of Elements of a 3-Dimensional Matrix

C Program To Multiply Two Matrices

#include<stdio.h>

int main()
{
    int arr1[3][3], arr2[3][3], arr3[3][3];
    int i, j, k, sum = 0;
    printf("Enter First 3*3 Matrix Elements:\n");
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            scanf("%d", &arr1[i][j]);
        }
    }
    printf("\nEnter Second 3*3 Matrix Elements:\n");
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            scanf("%d", &arr2[i][j]);
        }
    }
    printf("\nMultiplication of Matrices:\n");
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            for(k = 0; k < 3; k++)
            {
                sum = sum + arr1[i][k]*arr2[k][j];
            }
            arr3[i][j] = sum;   
            sum = 0;
        }
    }
    printf("\nThird Matrix Elements:\n");
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            printf("%d\t", arr3[i][j]);
        }
        printf("\n");
    }
    printf("\n");   
    return 0;
}

Also Read: C Program To Find Major and Minor Diagonals of a Matrix

 

Output

C Program To Multiply Two Matrices

If you have any Compilation Error or Doubts in this C Program for Multiplication of Two Matrices, let us know about it in the comment section below.

2 thoughts on “Multiply Two Matrices C Program

    1. Tushar Soni Post author

      Yes. We focus on keeping the program structure simple enough for the users to understand it effeftively.

      Reply

Let's Discuss