18 lines
234 B
Go
18 lines
234 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func add(nums ...int) int {
|
|
total := 0
|
|
for _, num := range nums {
|
|
total += num
|
|
}
|
|
return total
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println(add(1, 2, 3, 4))
|
|
nums := []int{1, 2, 3, 4, 5}
|
|
fmt.Println(add(nums...))
|
|
}
|