program circle real r, area c This program reads a real number r and prints c the area of a circle with radius r. write (*,*) 'Give radius r:' read (*,*) r area = 3.14159*r*r write (*,*) 'Area = ', area stop endThe lines that begin with a "c" are comments and have no purpose other than to make the program more readable for humans. Originally, all Fortran programs had to be written in all upper-case letters. Most people now write lower-case since this is more legible, and so will we. You may wish to mix case, but Fortran is not case-sensitive, so "X" and "x" are the same variable.
program name declarations statements stop endIn this tutorial, words that are in italics should not be taken as literal text, but rather as a description of what belongs in their place.
The stop statement is optional and may seem superfluous since the program will stop when it reaches the end anyway, but it is recommended to always terminate a program with the stop statement to emphasize that the execution flow stops there.
You should note that you cannot have a variable with the same name as the program.
Col. 1 : Blank, or a "c" or "*" for comments Col. 1-5 : Statement label (optional) Col. 6 : Continuation of previous line (optional; see below) Col. 7-72 : Statements Col. 73-80: Sequence number (optional, rarely used today)Most lines in a Fortran 77 program starts with 6 blanks and end before column 72, i.e. only the statement field is used.
c The next statement goes over two physical lines
area = 3.14159265358979
+ * r * r
Any character can be used instead of the plus sign as a continuation
character. It is considered good programming style to use either the plus
sign, an ampersand, or digits (using 2 for the second line, 3 for the third,
and so on).
Copyright © 1995-7 by Stanford University. All rights reserved.
[ME-390 Home
Page][Fortran
77 Tutorial Home]
hargrove@sccm.Stanford.EDU