
% Lab 6 Solutions
% CS 1109, Summer 2011
% July 14

% This script prints the following sequence of numbers to the screen:
% 0, -2, 4, -6, 8, ..., 48, -50


% There are two patterns to observe here. First, the numbers are all the
% even numbers from 0-50. Second, all multiples of 4 are printed as is;
% non-multiples of 4 are negated. Based on this, we can use the loop below.
for i = 0:2:50
   if (rem(i, 4) == 0)
       fprintf('%d ', i);
   else
       fprintf('%d ', -i);
   end
end

fprintf('\n');


