Chapter
61
Arrays
This program creates a 1-dimensional array:
5
C L S : O P T I O N B A S E 1
1 0 D A T A GROCERY,GAS,CLOTHES
2 0 D I M A ( 3 )
3 0 FOR C
=
1 TO 3
4 0 READ NAMES$
5 0 P R I N T "ENTER
THE "NAMES$"
EXPENSE I N D O L L A R S "
6 0
I N P U T A ( C )
7 0 N E X T C
The DIM statement in Line 10 reserves space in memory for an
array named A with 3 elements. As you enter the expenses, the
grocery expense is stored in A(l), the gas expense in A(2) and
the clothes expense in A(3).
Add these lines to the program to print the contents of Array A:
1 0 0 RESTORE
1 1 0 FOR C
=
1 TO 3
1 2 0 READ NAMES$
1 3 0 P R 1 N T : P R I N T NAMES$
"
=
"
A ( C )
1 4 0 N E X T C
Use RUN to see the results of this program.
You can add more dimensions to the array such as storing the
expenses by weeks.
Col 1
Col 2
Col 3
Grocery
Gas
Clothes
Row 1
Week 1
Row 2
Week 2
Row 3
Week 3
Row 4
Week
4
A(3,2)
=
Gas expense
for Week 3
60