- 2071 Shrawan · 8 marks
Formatted and unformatted I/O in FORTRAN
Short answer
Formatted I/O uses a FORMAT statement with edit descriptors (e.g., 2I4) to control output; example: WRITE(*,20) L,B. Unformatted I/O uses READ * (list‑directed) or binary file I/O without a format.
What do you mean by formatted and unformatted input/output statements in Fortran and also give suitable example which explain the concept of Formatted I/O?
Formatted input/output
In formatted I/O the programmer controls the exact form of the data by a FORMAT statement (edit descriptors) referred to by a label in READ or WRITE. Data are converted between their internal form and readable text.
Syntax: WRITE(unit, label) list and label FORMAT(descriptors)
Common descriptors: Iw integer, Fw.d real with d decimals, Ew.d exponent form, Aw character, nX n blanks, / new line, and quoted text.
Unformatted input/output
- List-directed (free format):
READ *, A, BandPRINT *, A, B(orREAD(*,*)) do not use a FORMAT. The computer decides the layout, with values separated by blanks or commas. Many textbooks call this unformatted I/O. - In the strict sense, unformatted I/O means writing and reading the internal binary form to a file (
OPEN(..., FORM='UNFORMATTED'), thenWRITE(10) list). It is fast, with no conversion, but not readable by people.
Example of formatted I/O
PROGRAM RECT
INTEGER L, B
REAL A
READ(*,10) L, B
A = L * B
WRITE(*,20) L, B, A
10 FORMAT(2I4)
20 FORMAT(' LENGTH =', I4, ' BREADTH =', I4, /, ' AREA =', F8.2)
STOP
END
For input 12 5 the output is
LENGTH = 12 BREADTH = 5
AREA = 60.00
2I4 reads two integers of width 4, F8.2 prints a real in 8 columns with 2 decimals, and / starts a new line.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Formatted vs unformatted I/O · Computer Programming, chapter 4 · asked 4×
- Formatted I/O in FORTRAN with syntax · Computer Programming, chapter 11
- Pattern: PULCHOWK using unformatted output · Computer Programming, chapter 4
- Output of printf statements · Computer Programming, chapter 4
- Pattern N, eee, PPPPP using unformatted I/O · Computer Programming, chapter 4
- Four-quadrant multiplier: concept and output · Advanced Electronics, chapter 6
- Output of e^(−2t)u(t) to a rectangular input · Signals and Systems, chapter 5 · asked 4×
- CE configuration input/output characteristics · Basic Electronics Engineering, chapter 3 · asked 3×
- LTI output for h(t)=e^(-2t), rectangular input · Data Communication, chapter 2 · asked 3×