Matrix Substraction
Algorithm
Input Two matrices a and b Output Output matrix c containing elements after subtraction of b from a complexity O(n^2) Matrix-Subtraction(a,b) 1 for i =1 to rows [a] 2 for j =1 to columns[a] 3 Input a[i,j]; 4 Input b[i,j]; 5 C[i, j] = A[i, j] - B[i, j]; 6 Display C[i,j];
Algorithm Description
To subtract two matrices sufficient and necessary condition is “dimension of matrix A = dimension of matrix B.” Loop for each row in matrix A. Loop for each column in matrix B. This loop will run for each rows of matrix A. Subtract B[i,j] from A[i,j] and store this value to C[i,j]; Return output matrix C.
C Code