forked from kishanrajput23/leetcode-solutions-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.c
More file actions
65 lines (52 loc) · 1.54 KB
/
Matrix.c
File metadata and controls
65 lines (52 loc) · 1.54 KB
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
60
61
62
63
64
65
#include<stdio.h>
#include <conio.h>
int main(){
int a[10][10],b[10][10],c[10][10],d[10][10], row, col,i,j;
printf("Enter the rows number of both matrices\n");
scanf("%d",&row);
printf("Enter the columns number of both matrices\n");
scanf("%d",&col);
printf("Enter the elements of matrix A\n");
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
printf("Enter the element at [%d%d] : ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("Enter the elements of matrix B\n");
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
printf("Enter the element at [%d%d] : ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}
printf("The addition of A and B is \n\t\t");
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
c[i][j]=a[i][j] + b[i][j];
}
}
//printing addition
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
printf(" %d ",c[i][j]);
}
printf("\n\t\t");
}
printf("\nThe subtraction of A and B is \n\t\t");
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
d[i][j]=a[i][j] - b[i][j];
}
}
//printing subtraction
for(i=0;i<row;i++){
for(j = 0;j < col;j++){
printf(" %d ",d[i][j]);
}
printf("\n\t\t");
}
return 0;
}