/* Sum of two Matrices. */
#include <stdio.h>
int main()
{
int n, m, i, j;
printf("Enter the number of rows and columns of matrices: ");
scanf("%d %d", &n, &m);
int a[n][m], b[n][m];
for(i = 0; i < n; i++){
for(j = 0; j < m; j++){
printf("Enter element (%d, %d) of matrices A and B: ", i+1, j+1);
scanf("%d %d", &a[i][j], &b[i][j]);
}
}
printf("The matrix A you entered is.....\n");
for(i = 0; i < n; i++){
for(j = 0; j < m; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
printf("The matrix B you entered is.....\n");
for(i = 0; i < n; i++){
for(j = 0; j < m; j++)
printf("%d\t", b[i][j]);
printf("\n");
}
printf("Sum of matrices A and B is.....\n");
for(i = 0; i < n; i++){
for(j = 0; j < m; j++)
printf("%d\t", a[i][j]+b[i][j]);
printf("\n");
}
return 0;
}
Comments
Post a Comment