Hi there, I'm trying to make a prime sieve, without using the functions primes(n) or isprime and I'm having trouble with getting my while loop to loop around.
% code
function [p,c] = sieve(N)X=ones(1,N);A=ceil(sqrt(N));p=[1:N];D=[2:A];m=1;n=1;while (m<=N && n<=A && p(m)<D(n)) if mod(p(m),D(n))==0 p(m)=0 X(m)=0 n=n+1 else m=m+1endpc=cumsum(X)end
Best Answer