#include <stdio.h> main() { int a[10][10], b[10][10], c[10][10], i, j, row, col; /* Reading Total count of rows and coloumns */ printf("\nEnter number of rows and columns of Matrix: "); scanf("%d %d", &row, &col); /* Reading First Array Elements */ printf("\nEnter Elements of an Array A:\n"); for (i=0; i<row; i++) for (j=0; j<col; j++) scanf("%d", &a[i][j]); /* Reading Second Array Elements */ printf("\nEnter Elements of an Array B:\n"); for (i=0; i<row; i++) for (j=0; j<col; j++) scanf("%d", &b[i][j]); /* Printing entered Values in MATRIX Form */ printf("\nElements of Matrix A are:\n\n"); for (i=0; i<row; i++) { for (j=0; j<col; j++) printf("\t%d", a[i][j]); printf("\n\n"); } printf("\nElements of Matrix B are:\n\n"); for (i=0; i<row; i++) { for (j=0; j<col; j++) printf("\t%d", b[i][j]); printf("\n\n"); } // Logic for adding matrices A and B for (i=0; i<row; i++) for (j=0; j<col; j++) c[i][j] = a[i][j] + b[i][j]; /* Printing the Final Result of SUM */ printf("\nMatrix Addition is:\n\n"); for (i=0; i<row; i++) { for (j=0; j<col; j++) printf("\t%d", c[i][j]); printf("\n"); } getch(); }
OUTPUT:
Enter number of rows and columns of Matrix: 3 3 Enter Elements of an Array A: 1 1 1 1 1 1 1 1 1 Enter Elements of an Array B: 2 2 2 2 2 2 2 2 2 Elements of Matrix A are: 1 1 1 1 1 1 1 1 1 Elements of Matrix B are: 2 2 2 2 2 2 2 2 2 Matrix Addition is: 3 3 3 3 3 3 3 3 3