Let A and B be the two matrix. The size of matrix A is m and size of matrix B. Then, find subtraction of C, is a A and B is defined as C(ij) = A(ij) - B(ij).
#include <stdio.h>
 Â
int main()Â Â
{Â Â
  int i, j,r,cl, A[10][10], B[10][10], C[10][10]; Â
  printf("Enter the number of rows and columns of matrix\n"); Â
  scanf("%d%d", & i, & j); Â
  printf("Enter the elements of matrix A\n"); Â
  for (r = 0; r < i; r++){
    for (cl = 0; cl < j; cl++){
      scanf("%d", & A[r][cl]);
    }
  } Â
     Â
  printf("Enter the elements of matrix B\n"); Â
  Â
  for (r = 0; r < i; r++) {
    for (cl = 0; cl <j; cl++){
      scanf("%d", & B[r][cl]);Â
    }
  }Â
     Â
  printf("Difference of entered matrices:\n");Â
  Â
  for (r = 0; r < i; r++) Â
  { Â
    for (cl = 0; cl < j; cl++) Â
    { Â
      C[r][cl] = A[r][cl] - B[r][cl]; Â
      printf("%d\t", C[r][cl]); Â
    } Â
    printf("\n"); Â
  } Â
  return 0; Â
}Â
Comments
Leave a comment