Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Sieve Of Eratosthenes

public static bool[] SieveOfEratosthenes(int num)
{
    bool[] isPrime = new bool[num + 1];
    for (int i = 2; i <= num; i++) isPrime[i] = true;
    // Removing multiples.
    for (int i = 2; i <= num; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * 2; j <= num; j += i) 
            	isPrime[j] = false; // Eliminate multiples of i.                
        }
    }
    return isPrime;
}
Source by paiza.io #
 
PREVIOUS NEXT
Tagged: #Sieve #Of #Eratosthenes
ADD COMMENT
Topic
Name
7+2 =