#include <stdio.h>
int main() {
int M[2][2], N[2][2], sum[2][2];
int i, j;
// Input elements of matrix M
printf("Enter elements of matrix M (2x2):\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("M[%d][%d]: ", i, j);
scanf("%d", &M[i][j]);
}
}
// Input elements of matrix N
printf("Enter elements of matrix N (2x2):\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("N[%d][%d]: ", i, j);
scanf("%d", &N[i][j]);
}
}
// Calculate sum of matrices
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
sum[i][j] = M[i][j] + N[i][j];
}
}
// Display sum of matrices
printf("Sum of matrices M and N:\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
return 0;
}
0 Comments
I really appreciate for your words. Thank you very much for your comment.