# C Program to Subtract Two Matrices

## Subtract Two Matrices in C

To subtract two matrices in C programming, you have to ask to the user to enter the two matrix, then start subtracting the matrices i.e., subtract matrix second from matrix first like mat1[0][0]-mat2[0][0], mat1[1][1]-mat2[1][1], and so on. Store the result in the third matrix say mat3[0][0], mat3[1][1], and so on.

## C Programming Code to Subtract Two Matrices

Following C program ask to the user to enter the two 3*3 array elements to subtract them i.e., Array1 - Array2, then display the subtracted array i.e, Array3 on the screen which is the result of Array1 - Array2:

```/* C Program - Subtract Matrices */

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int arr1[3][3], arr2[3][3], arr3[3][3], sub, i, j;
printf("Enter 3*3 Array 1 Elements : ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&arr1[i][j]);
}
}
printf("Enter 3*3 Array 2 Elements : ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&arr2[i][j]);
}
}
printf("Subtracting array (array1-array2) ... \n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
arr3[i][j]=arr1[i][j]-arr2[i][j];
}
}
printf("Result of Array1 - Array2 is :\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d ", arr3[i][j]);
}
printf("\n");
}
getch();
}```

When the above c program is compile and executed, it will produce the following result:

### Same Program in Other Programming Language

You may also like same program in other programming languages:

Tools
Calculator