SHARE
TWEET

Swift: solution to challenge p12 (Swift Programming Lang)

applehelpwriter Jun 4th, 2014 194 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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top