-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_matrix.c
44 lines (36 loc) · 1 KB
/
add_matrix.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
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#define ROWS 6
#define COLS 6
int main() {
int m1[ROWS][COLS], m2[ROWS][COLS], sum[ROWS][COLS];
int i, j;
// Initialising 2 Matrices
printf("Enter first Matrix: ");
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
printf("Enter Matrix 1 [%d][%d]: ", i, j);
scanf("%d", &m1[i][j]);
}
}
printf("Enter second Matrix: ");
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
printf("Enter Matrix 2 [%d][%d]: ", i, j);
scanf("%d", &m2[i][j]);
}
}
/* Initialising the Sum Matrix, by adding corresponding elements of matrix */
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
sum[i][j] = m1[i][j] + m2[i][j];
}
}
// Displayig the SUM Matrix
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
printf("%d\t", sum[i][j]);
}
printf("\n");
}
return 0;
}