Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

% Read in user number number = input(\'Enter number (-999 to quit)\'); % Repeat

ID: 3637978 • Letter: #

Question

% Read in user number
number = input('Enter number (-999 to quit)');

% Repeat number until user has read -999
while number ~= -999
% Read in number from user
number = input('Enter number (-999 to quit)');
end

Modify the above program to populate (fill) a one dimensional array (row vector) with the values read in from the user until they enter -999. Hint: use a while loop and array concatenation keeping in mind that array concatenation is inefficient but without knowing the number of values to be read in is necessary.

Use the following comment skeleton:

% initialize empty array
arr = [];
% read in first number from user
% while number is not -999 repeat % save number in array
% read in number from user

Explanation / Answer

array=zeros(1,1); number = input('Enter number (-999 to quit)'); i=1; while number ~= -999 array(1,i)=number; i=i+1; number = input('Enter number (-999 to quit)'); end array