-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix-sum.c
39 lines (30 loc) · 748 Bytes
/
matrix-sum.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
#include <stdio.h>
#define N 2
main()
{
int A[N][N], B[N][N], C[N][N];
printf("Enter Matrix A (%d x %d) row-wise\n", N, N);
for(int i=0; i < N; ++i) {
for(int j = 0; j < N; ++j){
scanf("%d", &A[j][i]);
}
}
printf("Enter Matrix B (%d x %d) row-wise\n", N, N);
for(int i=0; i < N; ++i) {
for(int j = 0; j < N; ++j){
scanf("%d", &B[i][j]);
}
}
for(int i=0; i < N; ++i) {
for(int j = 0; j < N; ++j){
C[i][j] = A[i][j] + B[i][j];
}
}
printf("Sum of the two matrices A and B\n");
for(int i=0; i < N; ++i) {
for(int j = 0; j < N; ++j){
printf("%6d", C[i][j]);
}
printf("\n");
}
}