Advertisement
hassanbanat

array

Jan 8th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.53 KB | None | 0 0
  1. print("enter 5 numbes")
  2. var arr :[Int] = []
  3.  
  4. for _ in 0..<5 {
  5.     let number:String? = readLine()!
  6.     let z = Int (number!)!
  7.     arr.append(z)
  8.    
  9. }
  10. let total = arr.reduce(0, +)
  11.  
  12. print("array total: ",total)
  13. let total3 = arr.reduce(1, *)
  14. print("array multi: ",total3)
  15.  
  16. //let total2 = arr.reduce(0, +)/5
  17. print("array avg: ",total/arr.count)
  18.  
  19. for i in 0..<arr.count {
  20.    
  21.     print("arry + 5: ",arr[i] + 5)
  22.    
  23.    
  24. }
  25. print("********")
  26. for i in 0..<arr.count {
  27.    
  28.     print("array * 3:",arr[i] * 3)
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement