- 2069 Asar · 4 marks
Two dimensional arrays in FORTRAN
Short answer
A two-dimensional array is declared as type name(rows, columns) or DIMENSION name(rows, cols), e.g., INTEGER A(3,4) for 3 rows and 4 columns. Subscripts start from 1 (by default) and storage is column-major; an element is referenced as A(i,j).
What is the syntax of two dimensional arrays in FORTRAN? Explain with example.
A two dimensional array is a table of rows and columns. It must be declared before use, either with a type statement or with DIMENSION.
Syntax
type name(rows, columns)
DIMENSION name(rows, columns)
Examples: INTEGER A(3,4) (3 rows, 4 columns, 12 elements) and REAL B(2,2).
- Subscripts start from 1 by default: A(1,1) is the first element. Other bounds can be given as
A(0:2, 0:3). - An element is written
A(i,j), row i and column j. - FORTRAN stores arrays in column-major order (the first subscript changes fastest).
- FORTRAN 77 allows up to seven dimensions.
- The subscripts can be integer expressions, and nested DO loops or nested implied DO are used to process them.
Example: read and print a 2×3 array
PROGRAM ARR2D
INTEGER A(2,3), I, J
READ *, ((A(I,J), J = 1, 3), I = 1, 2)
DO 10 I = 1, 2
PRINT *, (A(I,J), J = 1, 3)
10 CONTINUE
STOP
END
For input 1 2 3 4 5 6 it prints 1 2 3 and then 4 5 6.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Formatted I/O in FORTRAN with syntax · Computer Programming, chapter 11
- Array overflow/underflow; add two arrays · Computer Programming, chapter 7
- Sum of two matrices in FORTRAN · Computer Programming, chapter 11
- Creating 1D and 2D arrays · Computer Programming, chapter 7 · asked 2×
- Add and subtract matrices in FORTRAN · Computer Programming, chapter 11
- Significance of arrays; multiply 3×3 matrices · Computer Programming, chapter 7
- Antenna arrays and two-element expression · Propagation and Antenna, chapter 2
- Derive two-dimensional heat equation · Applied Mathematics, chapter 3 · asked 2×
- Need for arrays and two-element patterns · Propagation and Antenna, chapter 2
- OpenGL syntax: 3D vertex · Computer Graphics, chapter 9