C Program to Add Two Matrix
Write C Program to Add Two Matrix
// C Program to Add Two Matrix #include <stdio.h> int main() { int A[3][3] = { {1,2,3}, {3,4,6}, {1,2,3} }; int B[3][3] = { {4,5,6}, {1,2,3}, {1,4,9} }; int C[3][3], i, j; printf("Matrix A :--> \n"); for(i = 0;i < 3; i++) { for( j = 0; j < 3; j++) { printf("%d ", A[i][j]); } printf("\n"); } printf("\n\nMatrix B :--> \n"); for(i = 0;i < 3; i++) { for( j = 0; j < 3; j++) { printf("%d ", B[i][j]); } printf("\n"); } printf("\n\nAddition of Matrix A and B:--> \n"); for(i = 0;i < 3; i++) { for( j = 0; j < 3; j++) { C[i][j] = A[i][j] + B[i][j]; printf("%d ", C[i][j]); } printf("\n"); } return 0; }
Output:
Matrix A :-->
1 2 3
3 4 6
1 2 3
Matrix B :-->
4 5 6
1 2 3
1 4 9
Addition of Matrix A and B:-->
5 7 9
4 6 9
2 6 12