forked from akn714/1st-yr-c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
26.c
59 lines (49 loc) · 1.29 KB
/
26.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Task : WAP to add and multiply two matrices of order nxn
#include <stdio.h>
int main() {
int n, i, j, k;
// inputtting the size of array
printf("size of array? ");
scanf("%d", &n);
int mat1[n][n], mat2[n][n], sum[n][n], mult[n][n];
// inputting matrix 1
printf("enter 1st matrix :\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d", &mat1[i][j]);
}
}
// inputting matrix 2
printf("enter 2nd matrix :\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d", &mat2[i][j]);
}
}
// adding and multiplying two matrices
for(k=0;k<n;k++){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
sum[i][j] = mat1[i][j] + mat2[i][j];
mult[k][i] += mat1[k][j] * mat2[j][i];
}
}
}
// printing addition of 2 matrices
printf("addition of 2 matrices :\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ", sum[i][j]);
}
printf("\n");
}
// printing multiplication of 2 matrices
printf("multiplication of 2 matrices :\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ", mult[i][j]);
}
printf("\n");
}
return 0;
}