Arrays
Arrays
Built and Summed
An array constructor [a, b, c] initializes a fixed-shape array. sum adds all elements at once.
Program
Play the program to build a 4-element array and sum it.
arrays.f90
program arrays
implicit none
integer :: nums(4)
integer :: total
nums = [1, 2, 3, 4]
total = sum(nums)
print '(I0)', total
end program arrays
array constructor
`[1, 2, 3, 4]` builds a rank-1 array.
sum
`sum(nums)` reduces an array to one scalar.
one-based index
Fortran arrays start at index 1 by default.