## Write a C program to print the subtraction of two matrices

Write a C program to print the subtraction of two matrices. In this C Matrix example, we are going to create a program to find the substraction of two matrices.

## What are Matrices

Matrices are the rectangular or square arrays that are used in mathematics for certain operation

for example:

1    2     3

4      5     6

7     8      9

## Algorithm to subtraction two matrix

• Declare three 2d arrays and four variables.
• Then take four inputs, two for rows and column another two for the value of array a and b.
• Take three for loop.
• Print an appropriate subtraction of matrix in the last for loop.

## C program to subtraction two matrix

```#include<stdio.h>
void main (){
int a, b, d,r,c,row,column;
printf("enter the value of matrix row");
scanf("%d",&row);
printf("enter the value of matrix column");
scanf("%d",&column);
for(r=0;r<row;r++){
for(c=0;c<column;c++){
printf("\nenter the value of a");
scanf("%d",&a[r][c]);
}

}
printf("enter the value of ");
for(r=0;r<row;r++){
for(c=0;c<column;c++){
printf("\nenter the value of b");
scanf("%d",&b[r][c]);
}

}
for(r=0;r<row;r++){
for(c=0;c<column;c++){
d[r][c]=a[r][c]-b[r][c];
printf("%d ", d[r][c]);
}
printf("\n");
}

}```

## Explanation of this program

Step 1: Includes the library

Step 2: Declares the main method with the void.

Step 3: Declare three 2D arrays a,b, and d, and four variables.

Step 4:  Create four inputs first two for taking input from a user for row and column and another two for in loops for taking the array a and b.

Step 5:  Create three for loops first two for taking input of array a and b and the last one for print appropriate subtraction in array d.

Step 6: Give the condition and logic in for loop for subtraction and fo matrix

Step 7: Print \n for print in a sequence of a matrix.

Step 8: End.

## Output In this blog, we have learned how to create a program to find the subtraction of two matrices.