trying_out_go/cmd/headFirstCodeMagnets/variadic.go

19 lines
209 B
Go
Raw Permalink Normal View History

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