Skip to content

Instantly share code, notes, and snippets.

@comtom
Last active September 27, 2018 18:55
Show Gist options
  • Select an option

  • Save comtom/54d62b66bc7d3cc5372a0a104ab28e44 to your computer and use it in GitHub Desktop.

Select an option

Save comtom/54d62b66bc7d3cc5372a0a104ab28e44 to your computer and use it in GitHub Desktop.
func sum(nums ...int) {
fmt.Print(nums, " ")
total := 0
for _, num := range nums {
total += num
}
fmt.Println(total)
}
func main() {
sum(1, 2)
sum(1, 2, 3)
nums := []int{1, 2, 3, 4}
sum(nums...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment