Order this information in Print

Order this information on CD-ROM

Download in PDF Format

     

Click here to make tpub.com your Home Page

Page Title: Sample Problem Using Nested Loops and a Matrix
Back | Up | Next

tpub.com Updates

Google


Web
www.tpub.com

Home

   
Information Categories
.... Administration
Advancement
Aerographer
Automotive
Aviation
Combat
Construction
Diving
Draftsman
Engineering
Electronics
Food and Cooking
Math
Medical
Music
Nuclear Fundamentals
Photography
Religion
USMC
   
Products
  Educational CD-ROM's
Printed Manuals
Downloadable Books
   

 

Back
Working with arrays
Up
Introduction to Programming
Next
Using predefined functions

Back ] Home ] Up ] Next ]

Sample Problem Using Nested Loops and a Matrix

Suppose you wanted to write a program to compute your career sea pay based on your paygrade and years of sea duty. You would need a two-dimensional array (matrix) to store the data. Figure 5-1 shows the table of values needed to determine sea pay.

Examine the following program and see how the matrix is constructed. The program contains nested loops (lines 20-60) which are used to read the values into the matrix. The outer loop sets up the row portion, G, which represents paygrade. The inner loop sets up the column portion, S, which represents the years of sea duty.

Figure 5-1.—Sea-pay table.

Example:

As seen in the output from this program, an E-8 with 7 years sea duty would receive $285.00 sea pay. Try the program and see what your sea pay would be.

The paygrade (4-9) is entered (line 100). Before it can be used as a subscript to determine row number, we subtract 3 (line 110). This makes it correspond to row number 1-6. Next, years of sea duty (1-12) are entered to be used as the subscript for column number. Then the PRINT statement (line 140) prints the corresponding value of the coordinates G and S from the matrix named P.

Back ] Home ] Up ] Next ]

 

Privacy Statement - Press Release - Copyright Information. - Contact Us - Support Integrated Publishing