Programs and Problem Solving

A program is a list of instructions or program statements composed in such a way as to enable a computer to solve a problem. The problem to be solved is broken down into successively smaller parts. These parts should form a well defined structure, the large complex problem at the top the small easy to handle problems at the bottom. Hence the term top down programming.

To get a programming language to help you solve a problem, follow the steps below.

  1. State the problem in English
  2. Examine the problem and break down into several parts.
  3. Examine the parts and refine into smaller parts.
  4. Sketch a picture/structure plan
  5. Write the main program with references to the subprograms.
  6. Test the program.

It is important to note that the actual writing of the program is almost the last step.

Program Format

The positions within a line are called columns and are numbered 1, 2, 3, . . ., 80. All FORTRAN statements must be positioned in columns 7 through 72; characters that appear in columns 73 and beyond are ignored. If a statement re quires a statement label, this label must appear in columns 1 through 5. Statement labels must be integers in the range 1 through 99999.

Occasionally it may not be possible to write a complete FORTRAN statement using only columns 7 through 72 of a line. In this case, the statement may be continued on another line or lines (up to a maximum of 19), provided that a continuation indicator is placed in column 6 of the line(s) on which the statement is continued. This continuation indicator may be any alphabetic or numeric character other than a zero or a space. A zero or a space in column 6 indicates the first line of a statement.

Lines that contain only blanks or that have the letter C or an asterisk (*) in column 1 represent comment lines. Comments are not executed but, rather, appear only in the listing of the program unit. In standard FORTRAN, comments them selves may not be continued from one line to another by using a continuation indicator in column 6; instead, all comments must begin with a C or * in column 1.

Program Layout

The general form of a program in FORTRAN is

heading This statement marks the beginning of the program and gives it a name.
commented documentation This opening documentation contains info about the program's input, output and purpose.
specification part This includes the names and types of the constants and variables used to store input and output values as well as intermediate results are declared.
execution part This contains the statements that carry out steps of the algorithm.

Here is an example FORTRAN program:

* This program calculates the velocity and height of a projectile      *
* given its initial height, initial velocity, and constant             *
* acceleration.  Variables used are:                                   *
*    HGHT0   :  initial height                                         *
*    HGHT    :  height at any time                                     *
*    VELOC0  :  initial vertical velocity                              *
*    VELOC   :  vertical velocity at any time                          *
*    ACCEL   :  vertical acceleration                                  *
*    TIME    :  time elapsed since projectile was launched             *
*                                                                      *
* Input:   none                                                        *
* Output:  VELOC, HGHT                                                 *


       ACCEL = -9.807
       HGHT0 = 100.0
       VELOC0 = 90.0
       TIME = 4.3
       HGHT = 0.5 * ACCEL * TIME ** 2  +  VELOC0 * TIME  +  HGHT0

Work your way through the following components attempting the exercises as you come across them:

| Programs | Variables | Arithmetic Operations | Input and Output | Looping in Programs | Arrays in Programs | Checking variables | Subprograms and functions |