When to Use Subprograms?
Subprograms Are Small Programs That Are Written Within a Larger, Main Program. the Purpose of a Subprogram Is to Perform a Specific Task. This Task May Need to...
Subprograms are small programs that are written within a larger, main program. The purpose of a subprogram is to perform a specific task. This task may need to be done more than once at various points in the main program.
What are the main reasons for using subprograms?
There are several advantages to using subprograms:
- They help keep the code simple, and, thus, more readable;
- They allow the programmer to use the same code as many times as needed throughout the program;
- They allow the programmer to define needed functions; and,
- They can be used in other programs.
What are two reasons for using subprograms?
Two important advantages of using subprograms are reuse and abstraction. In our Sort program we saw how subprograms allow us to reuse the same code. Although the Sort program does many swaps, we only have to write the Swap procedure one time. Each call to Swap uses the same code that we wrote for the procedure.