function p=prime(n)

% First prime number.
p = 2;
j = 1;

while length(p) < n
    % Next number to consider.
    j = j+2;
    divisible = 0;
    
    for i = 1:length(p)
        
        if p(i) > sqrt(j)
            break;
        end
        
        if mod(j,p(i)) == 0
            divisible = 1;
            break;
        end
        
    end
    
    if divisible == 0
        p(length(p)+1) = j;
    end
end