Answers for "variadic function golang"

0

variadic function golang

package main
import "fmt"

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...)
}
Posted by: Guest on September-19-2021

Code answers related to "Assembly"

Browse Popular Code Answers by Language