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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #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

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.
please give the additon of three matrices by using three dimensional array..??