Menu Close

Arrays – FORTRAN

In Fortran, an array is a collection of elements of the same type, arranged in a specific order.

Arrays allow you to store and manipulate multiple values using a single variable name.

The elements in an array are accessed by their indices, which start from 1.

Example

In this program, we declare an array called numbers of size 5, which can store integer values.

We then assign values to each element of the array using the index notation numbers(index) = value.

program array_example
  implicit none
  
  ! Declare an array of integers
  integer :: numbers(5)
  integer :: i
  
  ! Assign values to the array elements
  numbers(1) = 10
  numbers(2) = 20
  numbers(3) = 30
  numbers(4) = 40
  numbers(5) = 50
  
  ! Print the array elements
  do i = 1, 5
    print *, numbers(i)
  end do
  
end program array_example

More Related Stuff