Subtraction of Two Matrix in C program

Subtraction of Two Matrix in C

In this example, you will get and learn the example code of subtraction of two matrix in c program.

Here, first we will get size of matrix, Input elements in matrix 1 and matrix 2, calculate the subtract matrices, and print the matrix 3 as result.

Write a c program to subtract two 3×3 matrices

To subtract two 3×3 matrices in C, use nested loops to iterate through rows and columns, subtracting corresponding elements and storing the result in a new matrix.

For example:

k[i][j] = p[i][j] – q[i][j]

where i, j are the rows and columns

Example program to subtract two matrices are the following.

Subtraction of Two Matrix in C program

Output

Enter No of Rows & Columns (max : 5,5) :3
3

Enter Elements for 1st Matrix :
1 2 3
6 5 4
8 7 6

Enter Elements for 2nd Matrix :
2 3 4
2 3 1
4 3 2

The Elements After Substraction :

-1 -1 -1
4 2 3
4 4 4

 

 

Check out our other C programming Examples

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top