 C Tutorial

# C program to compute matrix subtraction using two dimensional array

## C program to compute matrix subtraction using two dimensional array

This c program is used to compute the subtraction of two matrix using two dimensional array and nested for loops.

Defined the macro for row nad column size using define driective.

```a b c           g h i           a-g b-h c-i
d e f      -    j k l      =    d-j e-k f-l
g h i           m n o           g-m h-n i-o
```
```#include<stdio.h>

#define COLUMN 3
#define ROW 3

void main()
{
int matrix1[ROW][COLUMN], matrix2[ROW][COLUMN], matrix3[ROW][COLUMN], matrix4[ROW][COLUMN];
int i,j;

printf("\nEnter Matrix1: \n");
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
scanf("%d", &matrix1[i][j]);
}
}
printf("\nEnter Matrix2: \n");
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
scanf("%d", &matrix2[i][j]);
}
}
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
matrix3[i][j] = matrix1[i][j] - matrix2[i][j];
}
}
printf("\nMatrix Subtraction: \n");
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
printf("%d\t", matrix3[i][j]);
}
printf("\n");
}
}
```

Output:

```\$ cc matrix_subtraction.c
\$ ./a.out

Enter Matrix1:
11 12 13
14 15 16
17 18 19

Enter Matrix2:
1 2 3
4 5 6
7 8 9

Matrix Subtraction:
10	10	10
10	10	10
10	10	10
\$ ./a.out

Enter Matrix1:
1 2 3
4 5 6
7 8 9

Enter Matrix2:
11 12 13
14 15 16
17 18 19

Matrix Subtraction:
-10	-10	-10
-10	-10	-10
-10	-10	-10
``` C Tutorial

## C Examples

Privacy Policy  |  Copyright 2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page     