-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixAdd.c
32 lines (32 loc) · 857 Bytes
/
MatrixAdd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
int main() {
int r, c;
printf("Enter the number of rows and columns: ");
scanf("%d %d", &r, &c);
int m1[r][c], m2[r][c], sum[r][c];
printf("Enter elements of the first matrix:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &m1[i][j]);
}
}
printf("Enter elements of the second matrix:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &m2[i][j]);
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
sum[i][j] = m1[i][j] + m2[i][j];
}
}
printf("Sum of the matrices:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
return 0;
}