Skip to main content

Structure of a FORTRAN program

Short answer

A FORTRAN program (fixed form) has optional PROGRAM statement, specification (INTEGER, REAL, etc.), executable statements, optional STOP, and mandatory END. Subprograms follow. Columns 1-5 for labels, 6 continuation, 7-72 code, 73-80 ignored.

Explain the structure of a FORTRAN program.

A FORTRAN (FORTRAN 77) program is made of statements written in a fixed layout. It has the following structure:

  1. Program heading (optional): PROGRAM name.
  2. Specification (declaration) statements: INTEGER, REAL, DOUBLE PRECISION, CHARACTER, LOGICAL, DIMENSION, PARAMETER. These come before any executable statement.
  3. Executable statements: assignment, input/output (READ, WRITE, PRINT), control (IF, DO, GOTO) and calls.
  4. STOP (optional) to end execution, and END, which must be the last statement.
  5. Subprograms (functions and subroutines) may follow the main program, each with its own END.

Layout rules (fixed form)

ColumnsUse
1C or * here makes the line a comment
1-5Statement label (number)
6Any character except 0 or blank: continuation of the previous line
7-72The statement
73-80Ignored (used for sequence numbers)

Example

C     AREA OF A CIRCLE
      PROGRAM CIRCLE
      REAL R, A
      PARAMETER (PI = 3.14159)
      READ *, R
      A = PI * R * R
      PRINT *, 'AREA = ', A
      STOP
      END

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →