Swift - Write program to write a function that takes in a variable number of Int parameters and returns the sum of all the arguments.

Requirements

Write a function that takes in a variable number of Int parameters and returns the sum of all the arguments.

Demo

func sum(nums: Int...) -> Int {
        var sum = 0
        for num in nums {
            sum += num//  w  w  w .jav  a 2s.c o  m
        }
        return sum
}

Related Exercise