Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

sieve

internal class Program
{
  public static void Main()
  {
    var n = 53;
    var prime = SieveOfEratosthenes(n);
    for (int i = 2; i <= n; i++)
    {
      if(prime[i] == 0)
      {
        Console.WriteLine(i); ;
      }
    }

  }
  public static int[] SieveOfEratosthenes(int num)
  {
    var isPrime = new int[num + 1];
    for (int i = 2; i <= num; i++)
    {
      if (isPrime[i]==0)
      {
        for (int j = i * 2; j <= num; j += i)
        {
          // Eliminate multiples of i.   
          isPrime[j] = 1;
        }
      }
    }
    return isPrime;
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# webapi return file 
Csharp :: check if two timespans intersect c# 
Csharp :: Call Thread in C# 
Csharp :: unity c# find object position in array 
Csharp :: loading player preferences unity 
Csharp :: wpf relativesource 
Csharp :: select specific columns from datatable in c# using lambda 
Csharp :: kendo validator tries to validate hidden fields 
Csharp :: c# record 
Csharp :: get after point in c# 
Csharp :: allow scroll with wheel mouse datagridview c# 
Csharp :: give an alias in model .net 
Csharp :: C# traverseall elements in class property 
Csharp :: c# substring find word 
Csharp :: get all properties of an object including children c# 
Csharp :: serialize xml as array C# 
Csharp :: C# check if object is default 
Csharp :: windows forms webbrowser refresh 
Csharp :: convert list to datatable c# 
Csharp :: c# asp.net hover tooltip 
Csharp :: stroke dash array wpf 
Csharp :: 405 - HTTP verb used to access this page is not allowed 
Csharp :: generate a dropdown list from array data using razor .net mvc 
Csharp :: select many vs select 
Csharp :: string.insert c# 
Csharp :: linq select to list 
Csharp :: except method c# 
Csharp :: dotnet create web api 
Csharp :: delete selected cells in Datagridview 
Csharp :: iis services in asp.net 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =