One solution of the problem Practice Program PP4.3 is:

! Ask a user to enter 15 numbers and then display the largest and the smallest

! number, with appropriate labels.

!

! Test your program using the following numbers

! 2,7,-13,8,19,5,-3,15,-6,21,-2,0,13,4,9

! read the numbers into the DO LOOP with a DATA statement

! then comment out the data statement and use the input statement

! Run "DO TRACE, fast (number, count, smallest, largest)" from command window (^j).

! Now run the do trace with "slow" instead of "fast".

! Make a temporary table of the values in the do loop.

! Comment out the "READ" (add !) and remove the ! from the "INPUT" statement

! to satisfy the problem as stated in the textbook.

 

LET maxnumber = 1e12 ! Could use the function "Maxnumber"...try it out!

LET smallest = maxnumber ! Assumes the smallest number is less than a trillion.

PRINT "Initially, smallest is ..."; smallest

LET largest = -maxnumber !Assumes the largest number is greater than minus a trillion.

PRINT "Initially, largest is ..."; largest

LET number = 0

LET count = 0

PRINT "count","number","largest", "smallest" ! ###temp header for loop values.

DO until count = 15 ! try moving this to the LOOP line.

LET count = count + 1

READ number ! comment this statement out for user input

!INPUT number ! replace the READ statement with this one for user input

IF number > largest then

LET largest = number

END IF

IF number < smallest then

LET smallest = number

END IF

PRINT count,number,largest, smallest ! ###temp, track loop values in a table.

LOOP

PRINT "The last sample of the data series was ... ";number !display last number

PRINT "The number of values considered was ... ";count ! display sample size

PRINT "The largest number is ... ";largest ! display largest in sample

PRINT "The smallest number is ... "; smallest ! display smalles in sample

DATA 2,7,-13,8,19,5,-3,15,-6,21,-2,0,13,4,9

END

The output of this form of the program is:

The smallest number is ... -13

Initially, smallest is ... 1.e+12

Initially, largest is ...-1.e+12

count number largest smallest

1 2 2 2

2 7 7 2

3 -13 7 -13

4 8 8 -13

5 19 19 -13

6 5 19 -13

7 -3 19 -13

8 15 19 -13

9 -6 19 -13

10 21 21 -13

11 -2 21 -13

12 0 21 -13

13 13 21 -13

14 4 21 -13

15 9 21 -13

The last sample of the data series was ... 9

The number of values considered was ... 15

The largest number is ... 21

The smallest number is ... -13