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.

func maxnumber(_ num1: Int, _ num2: Int, _ num3: Int) -> Int {
    if num1 > num2, num1 > num3 
    {
        return num1
    } 
    else if num2 > num3, num2 > num1 
    {
        return num2
    } 
    else if num3 > num2, num3 > num1 
    {
        return num3
    } 
    else if num1 == num2, num2 > num3 
    {
        return num1
    }
    else if num2 == num3, num3 > num1 
    {
        return num2
    } 
    else 
    {
        return num1
    }
}
print(maxnumber(-4, -5, 0))
print(maxnumber(11, 12, 13))
print(maxnumber(30, 20, 10))

Result

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

Leave a Comment