Subtract Matrix In C Programming

Introduction 
  • In this blog, I am going to explain how to subtract the matrix.
  • The program finds the difference between the two matrices.
Software Requirements 
  • Turbo C++ OR C 
Programming
  1. #include < stdio.h >   
  2. int main()   
  3. {  
  4.     int m, n, c, d, first[10][10], second[10][10], difference[10][10];  
  5.     printf("Enter the number of rows and columns of matrix\n");  
  6.     scanf("%d%d", & m, & n);  
  7.     printf("Enter the elements of first matrix\n");  
  8.     for (c = 0; c < m; c++)  
  9.         for (d = 0; d < n; d++) scanf("%d", & first[c][d]);  
  10.     printf("Enter the elements of second matrix\n");  
  11.     for (c = 0; c < m; c++)  
  12.         for (d = 0; d < n; d++) scanf("%d", & second[c][d]);  
  13.     printf("Difference of entered matrices:-\n");  
  14.     for (c = 0; c < m; c++)   
  15.     {  
  16.         for (d = 0; d < n; d++)   
  17.         {  
  18.             difference[c][d] = first[c][d] - second[c][d];  
  19.             printf("%d\t", difference[c][d]);  
  20.         }  
  21.         printf("\n");  
  22.     }  
  23.     return 0;  
  24. }  
Explanation 
  • In the programming given above, the subtraction of matrices can print the resultant elements in a simple manner.

    programming

    programming
Output

Output
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now