%Solution to problem 2 for the Sep 20-21 Lab session.
%Print all primes from 2 to N

N = input('Input N: ');

for i=2:N    

    % Check to see if i is prime
    d= 2;  % divisor to test
    while (mod(i,d)~=0)
        d= d+1;
    end
    iIsPrime= d==i;  % d=i only if i is Prime, otherwise d would be <i
                     % (See solution for function aPrime for details.)
    if iIsPrime
        fprintf('%d\n',i);
    end
end