Skip to content

Commit 2e5d7d7

Browse files
committed
Matrix Sum and difference in C language
1 parent eabf529 commit 2e5d7d7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Matrix.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<stdio.h>
2+
#include <conio.h>
3+
int main(){
4+
int a[10][10],b[10][10],c[10][10],d[10][10], row, col,i,j;
5+
6+
printf("Enter the rows number of both matrices\n");
7+
scanf("%d",&row);
8+
printf("Enter the columns number of both matrices\n");
9+
scanf("%d",&col);
10+
11+
12+
printf("Enter the elements of matrix A\n");
13+
for(i=0;i<row;i++){
14+
for(j = 0;j < col;j++){
15+
printf("Enter the element at [%d%d] : ",i,j);
16+
scanf("%d",&a[i][j]);
17+
}
18+
printf("\n");
19+
20+
}
21+
22+
printf("Enter the elements of matrix B\n");
23+
for(i=0;i<row;i++){
24+
for(j = 0;j < col;j++){
25+
printf("Enter the element at [%d%d] : ",i,j);
26+
scanf("%d",&b[i][j]);
27+
}
28+
printf("\n");
29+
30+
}
31+
32+
printf("The addition of A and B is \n\t\t");
33+
for(i=0;i<row;i++){
34+
for(j = 0;j < col;j++){
35+
c[i][j]=a[i][j] + b[i][j];
36+
}
37+
}
38+
//printing addition
39+
for(i=0;i<row;i++){
40+
for(j = 0;j < col;j++){
41+
printf(" %d ",c[i][j]);
42+
}
43+
printf("\n\t\t");
44+
}
45+
46+
47+
printf("\nThe subtraction of A and B is \n\t\t");
48+
for(i=0;i<row;i++){
49+
for(j = 0;j < col;j++){
50+
d[i][j]=a[i][j] - b[i][j];
51+
}
52+
}
53+
54+
//printing subtraction
55+
for(i=0;i<row;i++){
56+
for(j = 0;j < col;j++){
57+
printf(" %d ",d[i][j]);
58+
}
59+
printf("\n\t\t");
60+
}
61+
62+
63+
64+
return 0;
65+
}

0 commit comments

Comments
 (0)