Application
Create new folder named src. In src folder, create new file named main.go as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package main import "fmt" func main() { var a = [5]int{11, -4, 7, 8, -10} min, max := findMinAndMax(a) fmt.Println("Min: ", min) fmt.Println("Max: ", max) } func findMinAndMax(a [5]int) (min int, max int) { min = a[0] max = a[0] for _, value := range a { if value < min { min = value } if value > max { max = value } } return min, max } |
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
1 2 3 4 |
Min: -10 Max: 11 |