title: How to write a function that lists prime numbers using the sieve of Eratosthenes
body: <p>I am supposed to code a function or script that finds all prime numbers p smaller than a given integer n>2 using the "sieve of Eratosthenes" avoiding unecessary storage(I can create a vector of length n but not more)</p>
  
  <pre><code>n = input('Enter your number');
  v=[1:n];
  v(1)=0
  for i=2:n
      s=0;
      for j=v(2)
          if i&gt;v(2) &amp;&amp;  mod(i,j)==0
             s=s+1;
          end
      end
      if s&gt;0
        v(i)=0;
      end
  end
  for i=v(v&gt;v(find(v,1,'first'))):n
  s=0;
      for j=v(v&gt;v(find(v,1,'first')))
          if i&gt;v(v&gt;v(find(v,1,'first'))) &amp; mod(i,j)==0
             s=s+1
          end
      end
      if s&gt;0
        v(i)=0;
      end 
  end     
  
  v
  </code></pre>
  
  <p>I realize that this is very far from the code that I m supposed to write. But this is the only idea that came up to my mind and it only removes numbers which are divisible by 2 and 3,and I need to find all prime numbers,by repeating this for each entry.This is obviously not smart. But I feel that there can be created a loop for that. But I am failing to code this loop. Please help.</p>