March 2019
Intermediate to advanced
336 pages
9h 9m
English
The subtract method subtracts the elements of two 2 x 2 matrices. The subtract method in the following snippet subtracts the elements of matrix1 and matrix2. This method returns the resulting matrix after subtraction:
// subtract methodfunc subtract(matrix1 [2][2]int, matrix2 [2][2]int) [2][2]int { var m int var l int var difference [2][2]int for l = 0; l < 2; l++ { for m=0; m <2; m++ { difference[l][m] = matrix1[l][m] -matrix2[l][m] } } return difference}
The difference between two matrices is the result of calling the subtract method. The parameters that are passed are the matrices to be subtracted, as shown here:
var difference [2][2]intdifference = subtract(matrix1, matrix2)
The example output of the subtract method ...
Read now
Unlock full access