DIMension and arrays

Most BASICS allow you to use up to 10 rows and 10 columns in an array without any special preparation of the computer’s memory. Since arrays use up lots of memory, you must inform the system if you intend to use a larger array. In BASIC, this is done with the DIMension statement, which is contained in the first line of the next program. Enter:

NEW

10 DEFINT A: N=21: DIM A(N,N)If your system rebels at line 10, use:10 DEFINT A: N=21: DIM A(21,21)

The DIM statement in line 10 reserves enough memory for 21 rows and 21 columns of numbers. That gives you a total of 441 cells. Each cell takes up 2, 4, or 8 bytes, depending on the precision of the variables you use. The DEFINT restricts all variables that start with the letter A to be of the integer type (2 bytes); this definition saves mem- ory.

Filling arrays

Most computer systems set to 0 all numeric variables, including cells of arrays, at the beginning of a program. If your system does not automatically do this, use the following lines to perform the same function:

15 FOR X=0 TO N: FOR Y=0 TO N17 A(X,Y)=g: NEXT Y: NEXT X

To plot a figure in memory after all the cells are set to zero, you simply deposit ones in the correct positions using LET statements. For exam- ple, the statement A(2,3)=l will place a one in location (2,3).

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 can, however, use the standard distance formula (as in Figure 13-5) to calculate the distance from the center cell (11,ll) to each of the surrounding cells. If this distance is equal to 10, the cell content is changed to one; other- wise, the cell value remains zero.

176