Write a Swift program to test if an array of integers contains a 4 or a 8


Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. func checknumbers(_ a: [Int]) -> Bool {
  2. if a.contains(4) || a.contains(8)
  3. {
  4. return true
  5. }
  6. else
  7. {
  8. return false
  9. }
  10. }
  11. print(checknumbers([2, 6, 7]))
  12. print(checknumbers([4, 8]))
  13. print(checknumbers([4, 8, 5]))
  14.  

Result

swift programming languages techstudy.org

     





Related Topics





Popular Posts