%-------------------------------------% % Homework 6: Problem 2 % % Date: 10/22/2002 % % % % Gun Srijuntongsiri % % gs61 % % ?????? % %-------------------------------------% % Variables % --------- % numMultFive = number of multiples of 5 encountered so far. % curNum = last inputted number. numMultFive = 0; % Initialize to zero % Ask for the number in the sequence curNum = input('Enter a number (non-positive int = quit): '); % Continue doing if the number is positive while curNum > 0 % if it's multiple of five if mod(curNum,5)==0 numMultFive = numMultFive+1; % increase count of multiples of five. end % Ask for next number curNum = input('Enter a number (non-positive int = quit): '); end % Display output disp(['The number of multiples of five is ', num2str(numMultFive),'.']); % Other useful test cases are when % 1. the first number is non-positive, % 2. the entire sequence doesn't have any multiple of fives. % 3. the ending number (i.e. the non-positive number) is a multiple of five. % % Limitations are (1) not clear what to do if user enter a positive non-integer, % (2) when user enter the same number more than once, and if that number is % a multiple of five, say 5,5,5,5,-1, then it's not clear whether to say % the number of multiples of five is 4 or 1.