Advertisement
applehelpwriter

Swift: solution to challenge p12 (Swift Programming Lang)

Jun 4th, 2014
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //swift
  2. //get average of variable number or arguments
  3.  
  4. func averageOfArguments(args: Int...) -> Int {
  5.     var sum = 0
  6.     var avg = 0
  7.     for a in args {
  8.         sum += a
  9.     }
  10.     avg = sum / countElements(args)
  11.     return avg
  12. }
  13.  
  14. averageOfArguments(10,11,12,13,14)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement