-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix subtraction.c
53 lines (52 loc) · 1.34 KB
/
matrix subtraction.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
#include<stdio.h>
int main(){
int m,n,p,q;
int **arr1,**arr2,**arr3;
printf("Matrix-1:\n");
printf("Enter the numbers of rows: ");
scanf("%d",&m);
printf("Enter the number of columns: ");
scanf("%d",&n);
arr1=malloc(m*sizeof(int*));
for(int i=0;i<m;i++){
arr1[i]=malloc(n*sizeof(int));
}
printf("Enter the elements: \n");
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
scanf("%d",&arr1[i][j]);
}
}
printf("Matrix-2:\n");
printf("Enter the numbers of rows: ");
scanf("%d",&p);
printf("Enter the number of columns: ");
scanf("%d",&q);
arr2=malloc(p*sizeof(int*));
for(int i=0;i<p;i++){
arr2[i]=malloc(q*sizeof(int));
}
printf("Enter the elements: \n");
for(int i=0;i<p;i++){
for(int j=0;j<q;j++){
scanf("%d",&arr2[i][j]);
}
}
arr3=malloc(m*sizeof(int*));
for(int i=0;i<m;i++){
arr3[i]=malloc(q*sizeof(int));
}
for(int i=0;i<m;i++){
for(int j=0;j<q;j++){
arr3[i][j]=arr1[i][j]-arr2[i][j];
}
}
printf("________________________\n");
printf("Resultant Matrix:\n");
for(int i=0;i<m;i++){
for(int j=0;j<q;j++){
printf("%d ",arr3[i][j]);
}
printf("\n");
}
}