created variadic sum function

This commit is contained in:
John O'Keefe 2023-11-04 13:07:40 -04:00
parent f4b408cf92
commit 5f11ccf9f6

View File

@ -0,0 +1,18 @@
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))
}