To find the minimum of three numbers in Swift, you can use the built-in min
function.
In this example,
num1
, num2
, and num3
with specific values.min
function to find the minimum of num1
and num2
, and store the result in a temporary variable.min
function again to find the minimum of the temporary variable and num3
.min
function returns the smallest of the three values.import Foundation
let num1 = 5
let num2 = 10
let num3 = 3
let minOfFirstTwo = min(num1, num2)
let minimum = min(minOfFirstTwo, num3)
print("The minimum of \(num1), \(num2), and \(num3) is: \(minimum)")
The minimum of 5, 10, and 3 is: 3
In this example,
num1
, num2
, and num3
with specific values.min
function to find the minimum of num1
and num2
, and store the result in a temporary variable.min
function again to find the minimum of the temporary variable and num3
.min
function returns the smallest of the three values.import Foundation
let num1 = 15.5
let num2 = 10.3
let num3 = 12.8
let minOfFirstTwo = min(num1, num2)
let minimum = min(minOfFirstTwo, num3)
print("The minimum of \(num1), \(num2), and \(num3) is: \(minimum)")
The minimum of 15.5, 10.3, and 12.8 is: 10.3
In this tutorial, we learned How to find the Minimum of Three Numbers in Swift language with well detailed examples.