Dimensioning An Array; Filling An Array - Epson FX-80 User Manual

Hide thumbs Also See for FX-80:
Table of Contents

Advertisement

DIMensioning an array
Most BASICs allow the use of up to 10 rows and 10 columns in an
array without any special preparation of the computer's memory.
However, arrays use up lots of memory, so the system must be in-
formed if you intend to use a larger array. In BASIC, this is done with
the DIMension statement. Start a NEW program:
NEW
1~
DEFINT A: N=21: DIM A(N,N)
15
r
Use DIM A(21,21)
if your
system rebels at line
1~
17~
LPRINT CHR$(27)"@I: STOP
The DIM statement in line 10 reserves enough memory for 21 rows
and 21 columns of numbers. That's 441 total cells, and each cell takes
up 2, 4, or 8 bytes, depending on the precision of the variables being
used. The DEFINT restricts all variables starting with the letter A to be
of the integer type (2 bytes), thus saving memory.
Filling an array
To fill the array with ones and zeros, you can use simple LET state-
ments. For example, A(2,3)
=
1 sets location (2,3) equal to 1, while
A(4,1)
=0
sets location (4,1) equal to
o.
Actually, most computer sys-
tems set all numeric variables, including arrays, to 0 each time a pro-
gram is run. If that is true on your system, then plotting a figure in
memory is simply a matter of depositing Is in the correct positions.
For example, suppose you want to plot a circle of radius 10 in the 21
row by 21 column array-definitely a job for a plotter! You could use
the distance formula from high school math (as in Figure 15-5) to
calculate the distance from the center cell
(11,11)
to each of the sur-
rounding cells. If this distance is equal to 10, the cell content is
changed to one; otherwise, the cell value remains zero.
Note: If your system does not initialize numeric variables, you'll have
to set each cell equal to zero.
170

Advertisement

Table of Contents
loading

Table of Contents