11 Introduction to Subprograms

A fundamental approach to solving large, complex problems is to break the problem down into smaller problems. Then, solutions can be found for these smaller problems and organized in such a manner as to address the original problem. In a similar way, problems that require long, complex FORTRAN code can be broken down into program units. In addition to the main program unit, FORTRAN programs can contain subprograms. Subprograms allow the programmer to organize programs in a logical, hierarchical fashion. The FORTRAN language provides for two types of subprograms: functions and subroutines. A function returns a single value; a subroutine may return one or more values. There are several advantages to using subprograms:

Example
Assume that this is the pseudo-code for a desired sequence of operations:
The program could be written with five program units: a main program and four subprograms.