PROG
Take the minimum of a set of numbers.
The last number in list is -1, the sentinel value which is not included
in count.
PED
To learn another way to take the minimum of a set of numbers.
DO LOOP INVARIANT
min is the minimum of all numbers in the list, except the current number,
Click here to view Unit 4.7 Pascal program.
The way we learned how to take the minimum will work most of the time. Unfortunately, there is a minor problem. We have to assume or guess some value that will be larger than the minimum of the numbers. This is used as the initial value of the minimum. We can get around the problem by the use of the code shown here.The code sets the minimum to the first number. Ater taking the minimum, we need to read in the second number to ensure that the do-loop invariant is initially true on entering the loop.
The extra if before the loop on lines 11 to 13 will handle the special case of no
numbers before the -1, the null list.