golang create array with values between two numbers
To create an array with values between two numbers in Go (golang), you can follow these steps:
- Declare the array variable using the var keyword.
- Use the make function to create the array with a specific length.
- Iterate through the array using a for loop and assign values to each element.
Here's an example of the code:
package main
import "fmt"
func main() {
var arr []int
min := 5
max := 10
length := max - min + 1
arr = make([]int, length)
for i := 0; i < length; i++ {
arr[i] = min + i
}
fmt.Println(arr)
}