The max
function is used to get the maximum of two arguments. We can get the maximum of two integers, two floats, or two characters.
max first_argument second_argument
This function takes two parameter values to compare and returns the greater value.
Let's have a look at the example below.
main::IO()main = do-- get max of two integersprint(max 5 10)-- get max of two floatsprint(max 154.0 34.0)-- get max of two charactersprint(max 'a' 'A')
In the above code:
max
function to get the max of two integer values.max
function to get the max of two float values.max
function to get the max of two characters. We also use the ASCII
value to compare the characters.