Skip to content

Commit 009d94b

Browse files
committed
Added two CPP files,for addition and subtraction of Matrices
1 parent e5dad3f commit 009d94b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

math/ADD_TWO_MATRIX

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//addition of matrix or subtraction of matrix
2+
#include<stdio.h>
3+
int main()
4+
{
5+
int a[10][10],b[10][10],x[10][10];
6+
int r,c;
7+
printf("\n Enter the order of matrix a (max 10x10):");
8+
scanf("%d%d",&r,&c);
9+
printf("enter the elements of matrix a: ");
10+
for (int i=0;i<r;i++)
11+
for (int j=0;j<c;j++)
12+
scanf("%d",&a[i][j]);
13+
printf("\n enter the elements of matrix b: ");
14+
for (int i=0;i<r;i++)
15+
for (int j=0;j<c;j++)
16+
scanf("%d",&b[i][j]);
17+
18+
for(int i=0;i<r;i++)
19+
for(int j=0;j<c;j++)
20+
x[i][j]=a[i][j]+b[i][j]; //for addition
21+
//x[i][j]=a[i][j]-b[i][j]; for subtraction
22+
23+
printf("now the elements of the resultant matrix x is: ");
24+
for(int i=0;i<r;i++)
25+
{
26+
for(int j=0;j<c;j++)
27+
printf(" %d",x[i][j]);
28+
printf("\n");
29+
}
30+
return 0;
31+
32+
}

math/SUBTRACT_TWO_MATRIX

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//addition of matrix or subtraction of matrix
2+
#include<stdio.h>
3+
int main()
4+
{
5+
int a[10][10],b[10][10],x[10][10];
6+
int r,c;
7+
printf("\n Enter the order of matrix a (max 10x10):");
8+
scanf("%d%d",&r,&c);
9+
printf("enter the elements of matrix a: ");
10+
for (int i=0;i<r;i++)
11+
for (int j=0;j<c;j++)
12+
scanf("%d",&a[i][j]);
13+
printf("\n enter the elements of matrix b: ");
14+
for (int i=0;i<r;i++)
15+
for (int j=0;j<c;j++)
16+
scanf("%d",&b[i][j]);
17+
18+
for(int i=0;i<r;i++)
19+
for(int j=0;j<c;j++)
20+
//x[i][j]=a[i][j]+b[i][j]; //for addition
21+
x[i][j]=a[i][j]-b[i][j]; //for subtraction
22+
23+
printf("now the elements of the resultant matrix x is: ");
24+
for(int i=0;i<r;i++)
25+
{
26+
for(int j=0;j<c;j++)
27+
printf(" %d",x[i][j]);
28+
printf("\n");
29+
}
30+
return 0;
31+
32+
}

0 commit comments

Comments
 (0)