August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, you are going to learn how to add and subtract matrices with the help of the addMat.go utility, which is going to be presented in three parts. The program uses slices to implement the required matrices.
The first part of addMat.go is as follows:
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
)
func random(min, max int) int {
return rand.Intn(max-min) + min
}
func negativeMatrix(s [][]int) [][]int {
for i, x := range s {
for j, _ := range x {
s[i][j] = -s[i][j]
}
}
return s
}
The negativeMatrix() function gets a slice input and returns a new slice where each of the integer elements of the original size is replaced with its opposite integer. As you will soon see, the elements of the ...
Read now
Unlock full access