Function with a variadic parameter that finds the greatest number in a list of numbers:
func max(xs ...int) int { var max int for i, x := range xs { if i == 0 || x > max { max = x // w w w . j a va2 s. c o m } } return max }
package main /* w ww . j a v a2 s.c om*/ import "fmt" func max(xs ...int) int { var max int for i, x := range xs { if i == 0 || x > max { max = x } } return max } func main() { var x = max(4,3,4,5,6) fmt.Println(x) }