Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




/* Find the greatest element in an array of ints */
proc nonrec max([*] int a) int:
    int INT_MIN = ~((~0) >> 1);
    int nmax, i;
    nmax := INT_MIN;
    for i from 0 upto dim(a,1)-1 do
        if a[i] > nmax then nmax := a[i] fi
    od;
    nmax 
corp
 
/* Test on an array */
proc nonrec main() void:
    type arr = [8] int;
    writeln("Maximum: ", max(arr(1,5,17,2,53,99,61,3)))
corp