Multiplication tables: Difference between revisions

m
Line 1,951:
 
===Traditional approach===
The usual style is to write whole lines at a go, traditionally to fast lineprinters. Producing a tabular layout is easy (four characters per field to allow room to print 144 with a space separator), the difficulty lies in having blank parts at the start of the line followed by results. Having results followed by blanks is normal. The simplest way to achieve this would be to have a CHARACTER*4 function IFMT4(n) that returns four spaces for n <= 0, otherwise the digits, similar to the above example. But the plan is to write a line of such function calls at a go (with n = 0 for unwanted results), and alas, very few Fortran implementations allow recursive use of the formatted I/O system - here one level would be inside the function to produce the result for N > 0, and the other is the original WRITE statement that invokes the function.
 
So instead, write the table by first writing a line to a CHARACTER variable then blanking out the unwanted part.
Line 2,013:
READ(in,"(I2,<N>I4)") N,(A(I),I = 1,N)
would read N as a two-digit integer, and, as the READ statement executes further, use that value of N both in the FORMAT text's interpretation and in the further processing of the READ statement.
 
===VAX FORTRAN===
<lang Fortran>
1,220

edits