6. FORMAT statement
The FORMAT statement specifies the form of the data
being read or written. If the form of the data remains
unchanged, the same format statement can be used for
reading and writing. Moreover, the same format statement
can be used for more than one input-output statements.
statement number FORMAT(sets of specifications).
Each specification set consists of three elements:
edit descriptor, field size, and decimal
location.
The edit descriptor specifies the type of the data.
The field size is the maximum no. of character positions
on input or output media.
The decimal location is expressed as the no. of places
from the right of the field.
Example:
FORMAT (Iw)
-
FORMAT (I5)
I is the edit descriptor specifying that the data
is of integer type and w is the field size/width
FORMAT (Fw.d)
106 FORMAT (F10.2)
F is the edit descriptor specifying that the data
is of real type, w is an integer indicating the field
size, and d is the decimal location expressed as the
no. of places form the right of the field.
Q.15. Locate the error, if any, in each of the
following WRITE-FORMAT pairs: (June
2002)
(i) WRITE (3, 35) X, Y, Z
35 FORMAT (1X, 3E 18.9)
(ii) WRITE (*, 40) A, J, B, C, K
40 FORMAT (F7.1, 8I, E6.2)
Ans. (i) No spaces are allowed in the specification
3E 18.9. So the specification 3E 18.9 must be written
as 3E18.9. Format specification of two variables (Y,
Z) is not defined.
(ii) The integer data must be in the form of
Iw. So 8I must be written as I8. Format specification
of two variables (C, K) is not defined.
Q.16. Locate the error, if any, in each of the
following WRITE-FORMAT pairs: (Dec.
99)
(i) WRITE (*, 30), A, B, N
30 FORMAT (F10.2, 3X, I8, 5X, I6)
(ii) WRITE (*, 40) A, J, B, C, K
40 FORMAT (F7.1X, I8, E6.2)
Ans. (i) In WRITE statement, comma is not
allowed after right parenthesis.
(ii) Format specification of two variables
(C, K) is not defined.
|