I am TA for introducing MATLAB, and the class has not yet studied the use of arrays (or in MATLAB, vectors). There is an exam, and one of the questions in the study guide is as follows:
[Hard problem] A mode is a number in the sequence that appears most often. The user is prompted to enter a sequence of non-negative numbers in non-decreasing order one after another. The user indicates the end of the sequence by entering a negative number. Write a script to get this user input and determine the sequence mode. If there are several modes, you can report any of them as a mode. Do not use arrays. The following is an example of execution:
Determine mode of a set of nonnegative integers.
Use a negative number to quit.
Give me a number: 70
Another number not smaller than the previous: 71
Another number not smaller than the previous: 80
Another number not smaller than the previous: 80
Another number not smaller than the previous: 80
Another number not smaller than the previous: 91
Another number not smaller than the previous: 93
Another number not smaller than the previous: -1
Mode is 80.
, .
- , ?
, , , , .