Anonymous user
Greatest element of a list: Difference between revisions
→{{header|Fortran}}
(→{{header|Scala}}: add reduce-based solution) |
|||
Line 244:
=={{header|Fortran}}==
{{works with|Fortran|2003}}
The intrinsic function <tt>max</tt> accepts any number of arguments. The type of these arguments can be integer, real, character, string of characters or arrays of these.
implicit none
▲<lang fortran>program maximum
write (*, '(i0)') &
& max (1, 2, 3)
write (*, '(f3.1)') &
& max (1.0, 2.0, 3.0)
write (*, '(a)') &
& max ('a', 'b', 'c')
write (*, '(a)') &
& max ('abc', 'bca', 'cab')
write (*, '(i0, 2 (1x, i0))') &
& max ([1, 8, 6], [7, 5, 3], [4, 2, 9])
write (*, '(f3.1, 2 (1x, f3.1))') &
& max ([1.0, 8.0, 6.0], [7.0, 5.0, 3.0], [4.0, 2.0, 9.0])
write (*, '(a, 2 (1x, a))') &
& max (['a', 'h', 'f'], ['g', 'e', 'c'], ['d', 'b', 'i'])
write (*, '(a, 2 (1x, a))') &
& max (['abc', 'hig', 'fde'], ['ghi', 'efd', 'cab'], ['def', 'bca', 'igh'])
end program
Output:
3
3.0
c
cab
7 8 9
7.0 8.0 9.0
g h i
ghi hig igh
=={{header|Groovy}}==
|