forked from aaryxn-g/Learn-C-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd.c
45 lines (37 loc) · 1.03 KB
/
Add.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
45
#include <stdio.h>
#define MAX 10
int main() {
int matrix1[MAX][MAX], matrix2[MAX][MAX], result[MAX][MAX];
int i, j, row, col;
// Input for first matrix
printf("Enter the number of rows and columns: ");
scanf("%d %d", &row, &col);
printf("Enter elements of first matrix:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
scanf("%d", &matrix1[i][j]);
}
}
// Input for second matrix
printf("Enter elements of second matrix:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
scanf("%d", &matrix2[i][j]);
}
}
// Adding two matrices
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
result[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
// Displaying the result matrix
printf("\nResultant Matrix after addition:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
return 0;
}