I am trying to program the 'sieve of eratosthenes' in visual basic. For those that don't know, it is an algorithm for making tables of primes. Sequentially write down the integers from 2 to the highest number n you wish to include in the table. Cross out all numbers which are divisible by 2 (every second number). Find the smallest remaining number . It is 3. So cross out all numbers which are divisible by 3 (every third number). Find the smallest remaining number . It is 5. So cross out all numbers which are divisible by 5 (every fifth number). Continue until you have crossed out all numbers divisible by , where is the floor function. The numbers remaining are prime. This procedure is illustrated in the above diagram which sieves up to 50, and therefore crosses out primes up to . If the procedure is then continued up to n, then the number of cross-outs gives the number of distinct prime factors of each number. (http://mathworld.wolfram.com/EratosthenesSieve.html [Broken])(adsbygoogle = window.adsbygoogle || []).push({});

I have some code. But how would you go about programming this? I have psuedocode in front of me and forgot to e-mail my other files to myself, but I will try to post what I have so far in the near future.

I was thinking about doing it with listboxes, arrays, and 'for loops'.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Sieve of Eratosthenes - Programming in VB

Loading...

**Physics Forums | Science Articles, Homework Help, Discussion**