Skip to main content

Formatted I/O in FORTRAN with syntax

Short answer

Syntax: READ/WRITE(unit, label) list with a FORMAT(label) (descriptors). Descriptors like Iw, Fw.d, 'text', / control layout. Inline format strings e.g. '(I5,F8.2)' are allowed.

Describe the formatted input and output statement in FORTRAN programming language with its syntax.

Formatted I/O uses a FORMAT statement to control how the data appears.

Syntax

      READ (unit, label) list
      WRITE (unit, label) list
label FORMAT (descriptor1, descriptor2, ...)
  • unit is the device number (* is the default keyboard/screen); label is the number of the FORMAT statement; list holds the variables.
  • The format can also be given inline: WRITE(*,'(I5,F8.2)') N, X.

Edit descriptors

DescriptorUseExample
IwInteger in w columnsI5
Fw.dReal, d decimalsF8.2
Ew.dReal in exponent formE12.4
AwCharacterA10
nXSkip n columns3X
'text'Literal text' TOTAL = '
/Next line/

Example

      N = 25
      X = 3.14159
      WRITE(*,10) N, X
   10 FORMAT(' N = ', I4, '  X = ', F7.3)

Output: N = 25 X = 3.142

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →