Add Two Matrices C Program

By | December 14, 2015

C Program To Add Two Matrices (3 D Array)

Learn How To Add Two Matrices in C Programming. It is important that we should know about the How A For Loop Works before getting further with the C Program Code.

Here, you have two 3 – Dimensional Matrices (Integer Arrays) and the Sum of each Element of particular Row and Column must be stored in the Third Array of same Row and Column.

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

Note: This C Program Find Sum of Two Matrices is developed in Linux Ubuntu Operating System and compiled with GCC Compiler.

C Program To Add Two Matrices

#include<stdio.h>

int main()
{
    int arr1[3][3], arr2[3][3], arr3[3][3];
    int i, j;
    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("\nAddition of Matrices:\n");
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            arr3[i][j] = arr1[i][j] + arr2[i][j];
        }
    }
    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

Add Two Matrices in C Programming Language using For Loop

If you have any compilation errors or doubts in this C Program To Calculate Addition of Two Matrices, let us know about in the Comment Section below.

One thought on “Add Two Matrices C Program

Let's Discuss