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