trying_out_go/headFirstCodeMagnets/variadic.go

19 lines
213 B
Go
Raw Normal View History

2023-11-04 13:07:40 -04:00
package main
import "fmt"
func sum(numbers ...int) int {
var sum int = 0
for _, number := range numbers {
sum += number
}
return sum
}
func main() {
fmt.Println(sum(4, 1, 9, 2))
fmt.Println(sum(7))
}