Tag Archives: Sieve of Eratosthenes

Use the yield statement in C#

An enumeration is a sequence of values that a program can enumerate over, for example, by using a foreach loop. In C# you can use the yield statement to make a method that returns an enumeration. The method that builds … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Use Euler’s Sieve to find prime numbers in C#

The Sieve of Eratosthenes is a simple way to make a list of prime numbers. The basic idea is to make an array of numbers. Starting with 2, cross out all multiples of 2 greater than 2. Next cross out … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , | 4 Comments

Use the Sieve of Eratosthenes to find prime numbers in C#

To use the Sieve of Eratosthenes, you start with a table (array) containing one entry for the numbers in a range between 2 to some maximum value. This table keeps track of numbers that are prime. Initially every number is … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , | 2 Comments