I am studying Go lang right now and I encountered a problem when trying to print inputted Array. My code is like this:
package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
set(n)
}
func set(n int) {
a := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&a[i])
}
for y := 0; y < n; y++ {
fmt.Println(a[y])
}
return
}
my problem is when Inputted a number as a size for the array, that number always get printed too. Like when I inputted 8 as the array size then followed by the array value for example 10 9 8 7 6 5 4 3 then I get the wrong output: 8 10 9 8 7 6 5 4.Iit should be 10 9 8 7 6 5 4 3.
go versioncommand.