008. Array intrinsic functions: sum, minval, maxval, minloc, findloc#

topic: Arrays

Fortran has many array intrinsic functions. Below, ! starts a comment.

array-intrinsics.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
integer, parameter :: vec(3) = [4, 1, 9]

print *, minval(vec), maxval(vec)  ! output: 1 9
print *, sum(vec), product(vec)  ! 14 36
print *, minloc(vec), maxloc(vec)  ! 2 3
print *, findloc(vec,9), findloc(vec,8)  ! 3 0

end
Output1#
           1           9
          14          36
           2           3
           3           0


1

Compiled using GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with no flags