Intel fortran-80 Laptop User Manual


 
CHAPTER
11
INTRODUCTION TO FORTRAN
This
chapter
opens
with a
short
example intended
to
give the newcomer
to
FOR-
TRAN
a feel
for
the language.
The
example
is
discussed in some d.etail.
The
chapter
also includes a
summary
of
FORTRAN-80
statements
and
their
proper
coding se-
quence.
1.1
An Introductory Example
A
FORTRAN
program
generally
performs
three basic
operations:
receiving
input,
processing the
data
received,
and
returning
output.
The
following
short
program,
drawn
from the statistical world
of
the
sports
fan(atic), shows typical
FORTRAN
statements
for doing these
operations.
The
example calculates a baseball
player's
batting
average using the
equation:
HITS
AVERAGE =
TIMES AT BAT
The
baseball statistician, sitting
at
his console terminal, enters the
name
of
a player,
how
often
he has
batted,
and
his
total
hits.
The
program
returns
a listing showing
the
player's
name
and
batting
average.
To
keep this example simple, the calculation
is
done
only once.
1.1.1 Comment Lines
The
first seven lines
of
the
example
are
comment
lines.
Comment
lines
are
used
to
document
a
program.
.
A
comment
line
must
have the letter
'C'
or
an
asterisk (*) in
column
1 followed by
any
characters
accepted by
FORTRAN
in the
remainder
of
the line. A completely
blank line
is
considered a
comment
line also.
For
example, the
'C'
need
not
be pre-
sent in line 7
of
the example.
Comment
lines have
no
effect
on
program
execution.
C CALCULATE BATTING AVERAGES
C VARIABLES
USED-
C PNAME = PLAYER'S
NAME
C AB = TIMES AT BAT
CHITS
= TOTAL BASE HITS
C AVG
= BATTING AVERAGE
C
CHARACTER*12 PNAME
READ
10, PNAME, AB, HITS
10
FORMAT
(A,
2(2X, F3.0))
AVG
= HITS/AB
PRINT 20,
PNAME, AVG
20
FORMAT (A, 5X, F4.3)
END
Fig. 1-1 Batting Average
Program
1-1