008. Array intrinsic functions: sum
, minval
, maxval
, minloc
, findloc
#
topic: Arrays
Fortran has many array intrinsic functions. Below, !
starts a comment.
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
1 9
14 36
2 3
3 0
Fortran has many array intrinsic functions. Below, ! starts a comment.
— FortranTip (@fortrantip) December 17, 2021
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
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags