Iterating over a 2D slice

Report a typo

Suppose you have a two-dimensional slice of integers that compose a 3x3 matrix:

matrix := [][]int{
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
}

Write a Go program that takes as an input an integer number num and then uses a nested for...range loop to print each element of the matrix in a new line, multiplied by num

Sample Input 1:

2

Sample Output 1:

2
4
6
8
10
12
14
16
18
Write a program in Go
package main

import "fmt"

func main() {
// DO NOT delete the code block below!
matrix := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
var num int
fmt.Scanln(&num)

// Use a nested for...range loop to print each element
// of the matrix in a new line, multiplied by 'num'
for _, row := range ? {
for _, ? := range ? {
fmt.Println(? * num)
}
}
}
___

Create a free account to access the full topic