
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

PROGRAM Example
 
  IMPLICIT NONE
  INTEGER :: rows, columns, errcheck
  INTEGER, ALLOCATABLE :: array(:,:)
 
  WRITE(*,*) "Enter number of rows"
  READ(*,*) rows
  WRITE(*,*) "Enter number of columns"
  READ(*,*) columns
 
  ALLOCATE (array(rows,columns), STAT=errcheck) ! STAT is optional and is used for error checking
 
  array(1,1) = 42
 
  WRITE(*,*) array(1,1)
 
  DEALLOCATE (array, STAT=errcheck)
 
END PROGRAM Example