We need to use a two-dimensional array to store the values in the following table:
|
|
|
Number
|
Square
|
Square root
|
Factorial
|
|
|
1
1.41421356237
1.73205080757
|
|
|
|
|
|
|
|
This table contains 3 rows and 4 columns for a total of 12 values.
|
|
If subscript numbering begins at 0, the elements are identified as follows:
|
|
|
|
D(0,0)=1
D(1,0)=2
D(2,0)=3
|
|
|
D(0,1)=1
D(1,1)=4
D(2,1)=9
|
|
|
D(0,2)=1
D(1,2)=1.41421356237
D(2,2)=1.73205080757
|
|
|
D(0,3)=1
D(1.3)=2
D(2.3)=6
|
|
|
|
|
|
|
|
|
Subscript
|
0
|
1
|
2
|
3
|
|
|
|
|
1
1.41421356237
1.73205080757
|
|
|
|
|
|
|
Each element in array D is specified by its location in the array with two subscripts,
separated by a comma, and enclosed within parentheses. The first subscript designates the
‘‘row’’ in the array; the second subscript designates the
‘‘column’’.
|
|
If numbering of the subscript begins with 1, array D would be represented:
|
|
|
Subscript
|
1
|
2
|
3
|
4
|
|
|
|
|
1
1.41421356237
1.73205080757
|
|
|
|
|
|
|
Thus, 9 would be represented as D(3,2); 6 would be represented as D(3,4).
|
|
Array names are the same as simple variable names; an array name may be a letter from
A through Z, or a letter immediately followed by a digit from 0 through 9. But whenever
an array is specified, it must be followed by subscripts enclosed within parentheses,
otherwise it specifies a simple variable. The range of each subscript is an integer from
0 through 32767, but the maximum array size is determined by available memory. A non-integer
subscript is rounded to the nearest integer if it is within the dimensioned range of
subscripts.
|
|
Arrays are extremely convenient for handling large groups of data within a program because
a group of different values are known under the same name. The different values (or
elements of the array) are distinguished in name by subscripts to the array name.
|
|
An array name followed by a single subscript enclosed within parentheses specifies a
one-dimensional array or an element of that array. An array name followed by two
subscripts separated by a comma, both enclosed within parentheses, specifies a
two-dimensional array or an element of that array. (No more than two subscripts are
allowed.) Whether the array name is understood as the whole array or as a specific element
depends on the type of statement that is used. Declaration statements refer to the whole
array, executable statements usually refer to an array element.
|