Swift - Write program to to find out the average of all the numbers from the array

Requirements

Write program to to find out the average of all the numbers from the array

Demo

var numbers = [5,6,3,2,4,8,1,0]
var sum = numbers.reduce (
       0,/*from  w ww. j  ava2 s.  c o  m*/
       {
           (sum: Int, num: Int) -> Int in
           return sum + num
       }
)
var average = Double(sum) / Double(numbers.count)
print(average)

Result

Related Exercise