Radio Shack TRS-80 Model 100 Basic Manual page 146

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Line 559 The numeric function INT is used in this line. This function drops any
fractional part of a number and thus returns the greatest integer less than or equal to
the argument. Consider the following examples
Argument x
1.234
239.899
4
Value of INT(x)
1
239
4
The values that are computed and assigned to the variables Nl and N2 are the middle
values for the subscripts of the array
S(I)
through
SeN).
For example, if N has the value 16, then
(N
+
1) / 2
=
8.5
(N
+
2) / 2
=
9
and
INT((N
+
1) / 2)
=
8
INT((N
+
2) / 2)
=
9
so that N1 and N2 will correctly contain the middle subscript values. Additional
examples are given in the table below:
N
30
20
13
27
(even)
(even)
(odd)
(odd)
N1
15
10
7
14
N2
16
11
7
14
Note that when N is even, Nt and N2 are the two middle values and when N is odd,
Nt and N2 are both equal to the single middle value. Thus, the use of the INT
function avoids any testing to determine whether N is even or odd.
Line 569 The median is calculated in this line. If N is even, then the average of the
two middle values is computed. If N is odd, then the values stored in NI and N2 are
the same and so the median is correctly calculated as the middle value.
Line 579 The median is displayed.
Now that you have a program which will sort an array of arbitrary length and compute
the median, you can use it as a sUbprogram in larger programs. The next experiment
shows you how to do this.
Experiment #7 Calculating the Median
for Each Weekday
In this experiment, the median sales will be calculated for each day of the week. This
means that the program should compute the median value of the six Monday sales, the
median value of the six Tuesday sales, and so on for each day of the week.
To accomplish this, the six values for each day must be sorted before the median can
be computed. The following program illustrates an efficient method of doing this.
140

Advertisement

Table of Contents
loading

Table of Contents