Write a Swift program to find the largest number among three given integers


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.  
  2. func maxnumber(_ num1: Int, _ num2: Int, _ num3: Int) -> Int {
  3. if num1 > num2, num1 > num3
  4. {
  5. return num1
  6. }
  7. else if num2 > num3, num2 > num1
  8. {
  9. return num2
  10. }
  11. else if num3 > num2, num3 > num1
  12. {
  13. return num3
  14. }
  15. else if num1 == num2, num2 > num3
  16. {
  17. return num1
  18. }
  19. else if num2 == num3, num3 > num1
  20. {
  21. return num2
  22. }
  23. else
  24. {
  25. return num1
  26. }
  27. }
  28. print(maxnumber(-4, -5, 0))
  29. print(maxnumber(11, 12, 13))
  30. print(maxnumber(30, 20, 10))

Result

swift programming languages techstudy.org

     





Related Topics





Popular Posts