*Design a program to process a sequence of non-negative integers, terminated by a single negative value and output the smallest value in the sequence.*

I did this problem after completing the 'Smallest and largest' problem, so this is just a simpler version of that problem.

`<?`

` // generate a random number of random numbers`

` for ($n = 0; $n < mt_rand(5, 20); $n++)`

` $sequence[] = mt_rand(1, 50);`

` `

` // add the terminator`

` $sequence[] = -1; `

` `

` // show the sequence`

` echo 'Sequence: ' . implode(', ', $sequence) . '<br/>';`

` `

` // sort the sequence of numbers`

` sort($sequence);`

` `

` // show the smallest`

` echo 'Smallest: ' . $sequence[1]; `

`?>`

Which produces:

Sequence: 40, 34, 3, 26, 12, 25, 18, 6, 14, 22, 42, -1

Smallest: 3

- May 2, 2005 - Added solution 1.

© 2004-20 robson | cc unless stated