To find the maximum of two numbers in Swift, you can use the built-in max
function.
In this example,
num1
and num2
with specific values.max
function to find the maximum of num1
and num2
.max
function returns the larger of the two values.import Foundation
let num1 = 5
let num2 = 10
let maximum = max(num1, num2)
print("The maximum of \(num1) and \(num2) is: \(maximum)")
The maximum of 5 and 10 is: 10
In this example,
num1
and num2
with specific values.max
function to find the maximum of num1
and num2
.max
function returns the larger of the two values.import Foundation
let num1 = 15.5
let num2 = 10.3
let maximum = max(num1, num2)
print("The maximum of \(num1) and \(num2) is: \(maximum)")
The maximum of 15.5 and 10.3 is: 15.5
In this tutorial, we learned How to find the Maximum of Two Numbers in Swift language with well detailed examples.