Averaging Two Sets Of One-Dimensional Arrays - IBM 5110 Basic Introduction

Table of Contents

Advertisement

108
The multiplier
a/ways
goes in parentheses so the system knows it is
not another array, and it must always go before the
*.
For division,
you merely multiply the array by 1 over the divisor, or by a decimal
number such as 0.5. Therefore, to divide each element of array A by
2, you would use this statement:
0080 C=(1/2)*A
Averaging Two Sets of One-Dimensional Arrays
If the weather data is kept in two sets of one-dimensional arrays, A
and 8 for temperature and C and D for rainfall, a program for
averaging the two sets of data and assigning the results to master
arrays T and R might look like this:
0010 DIM M$18(12),A(12),B(12),C(12),D(12),T(12),R(12)
00:::
0
~1(.:i
T
I~[AD
11' 1 :·
0030 DATA
JAN} FEB } MAR ,
ARP ,
MAY } JUNE , JULY ,
0040 DATA
SEPT, OCT , NOV
!
DEC
o
0
~:.:.i
(I
i\11:~i
T HE?)D (:"
J:-: ,
C , Ii
0060 DATA 20,21,22,23,24,25,2,27,28,29,3(1,31
0070
DATA
10,12,14,16,18
20,22,24,28,30,31
o
0
n
0
1:1
A T A 2) 2 } :2 , 2
1
:.3 , 3 , ::5 ,
I.j. , Lj .. '
' + ,
~.:.:.i
}
~:~i
o
0
(?
0 II
t,
T
tl
~5, ~:.i
.'
~:.i
)
' - I. , ' - I. ,
I.!. .'
~.::
,
:~.~
,
::? . ' 1
1
:3 ,
;.~~
o
:I. 0
(I
M
(:1
T T ::::
f~1
+ B
01:1.0 MAT T=(112)*T
0:1.20
M(~T
1?::::C+[t
0:1.30 MAT
R=(1/2)*R
0:1.40 FOR 1=1 TO 12
o
1
~j
(I
PHI N T F
I...
P
!
j . . . . .
j ~:. (
I ) . '
·r (
I ) . . F: ( I )
0160 NEXT I
0:1.70 f5TOP
We defined arrays T and R in the DIM statement on line 10, as well as
arrays M$, A, 8, C, and D. Note that we only need one array for the
names of the months, no matter how many years of data we have
stored in other arrays.
o
(-."'.
\\~._.i
108
The multiplier
a/ways
goes in parentheses so the system knows it is
not another array, and it must always go before the
*.
For division,
you merely multiply the array by 1 over the divisor, or by a decimal
number such as 0.5. Therefore, to divide each element of array A by
2, you would use this statement:
0080 C=(1/2)*A
Averaging Two Sets of One-Dimensional Arrays
If the weather data is kept in two sets of one-dimensional arrays, A
and 8 for temperature and C and D for rainfall, a program for
averaging the two sets of data and assigning the results to master
arrays T and R might look like this:
0010 DIM M$18(12),A(12),B(12),C(12),D(12),T(12),R(12)
00:::
0
~1(.:i
T
I~[AD
11' 1 :·
0030 DATA
JAN} FEB } MAR ,
ARP ,
MAY } JUNE , JULY ,
0040 DATA
SEPT, OCT , NOV
!
DEC
o
0
~:.:.i
(I
i\11:~i
T HE?)D (:"
J:-: ,
C , Ii
0060 DATA 20,21,22,23,24,25,2,27,28,29,3(1,31
0070
DATA
10,12,14,16,18
20,22,24,28,30,31
o
0
n
0
1:1
A T A 2) 2 } :2 , 2
1
:.3 , 3 , ::5 ,
I.j. , Lj .. '
' + ,
~.:.:.i
}
~:~i
o
0
(?
0 II
t,
T
tl
~5, ~:.i
.'
~:.i
)
' - I. , ' - I. ,
I.!. .'
~.::
,
:~.~
,
::? . ' 1
1
:3 ,
;.~~
o
:I. 0
(I
M
(:1
T T ::::
f~1
+ B
01:1.0 MAT T=(112)*T
0:1.20
M(~T
1?::::C+[t
0:1.30 MAT
R=(1/2)*R
0:1.40 FOR 1=1 TO 12
o
1
~j
(I
PHI N T F
I...
P
!
j . . . . .
j ~:. (
I ) . '
·r (
I ) . . F: ( I )
0160 NEXT I
0:1.70 f5TOP
We defined arrays T and R in the DIM statement on line 10, as well as
arrays M$, A, 8, C, and D. Note that we only need one array for the
names of the months, no matter how many years of data we have
stored in other arrays.
o
(-."'.
\\~._.i

Advertisement

Table of Contents
loading

Table of Contents