lab2 ex3
You cannot submit for this problem because the homework's deadline is due.
Ex3. Input of unknown length (20 marks)
Read a sequence of natural numbers from user input one by one, and store them in a row vector. Output this row vector.
The sequence has unknown length, but it ends with -1. The -1 is merely a signal for the end of input and should not be included in your output. Notice that -1 is a safe terminator value since it is not a natural number, but 0 for instance is not a safe terminator value. The length of the sequence can be 0, i.e., the sequence starts with -1, and in this case the output should be empty (disp([])
prints nothing!).
Hint: Which is more suitable for this exercise, for loop or while loop? Why?
Sample test cases
Input:
1
2
3
4
5
-1
Output:
1 2 3 4 5
Input:
-1
Output:
Format
You should submit a compressed file containing a Matlab source file ex3.m