C Programming Code Examples C > Arrays and Matrices Code Examples C Program to Add Two Matrix Using Multi-dimensional Arrays C Program to Add Two Matrix Using Multi-dimensional Arrays In this program, user is asked to entered the number of rows r and columns c. The value of r and c should be less than 88 in this program. The user is asked to enter elements of two matrices (of order r*c). Then, the program adds these two matrices, saves it in another matrix (two-dimensional array) and displays it on the screen. #include <stdio.h> int main(){ int r, c, a[88][88], b[88][88], sum[88][88], y, x; printf("Enter number of rows (between 1 and 88): "); scanf("%d", &r); printf("Enter number of columns (between 1 and 88): "); scanf("%d", &c); printf("\nEnter elements of 1st matrix:\n"); for(y=0; y<r; ++y) for(x=0; x<c; ++x) { printf("Enter element a%d%d: ",y+1,x+1); scanf("%d",&a[y][x]); } printf("Enter elements of 2nd matrix:\n"); for(y=0; y<r; ++y) for(x=0; x<c; ++x) { printf("Enter element a%d%d: ",y+1, x+1); scanf("%d", &b[y][x]); } // Adding Two matrices for(y=0;y<r;++y) for(x=0;x<c;++x) { sum[y][x]=a[y][x]+b[y][x]; } // Displaying the result printf("\nSum of two matrix is: \n\n"); for(y=0;y<r;++y) for(x=0;x<c;++x) { printf("%d ",sum[y][x]); if(x==c-1) { printf("\n\n"); } } return 0; }