Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

prime number generator

using System;
public class Program
{
    static void Main(string[] args)
    {
        var results = GenerateSieve(1000);
        var i=0;
        foreach (var item in results)
        {
            if(item) Console.Write(i + " ");
            i++;
        }
    }
 
    static bool[] GenerateSieve(int num)
    {
        // Creating an array indicating whether numbers are prime.
        bool[] isPrime = new bool[num + 1];
        for (int i = 2; i <= num; i++) isPrime[i] = true;
 
        // Removing out multiples.
        for (int i = 2; i <= num; i++)
        {
            // Check if i is prime.
            if (isPrime[i])
            {
                // Eliminate multiples of i.
                for (int j = i * 2; j <= num; j += i)
                    isPrime[j] = false;
            }
        }
        return isPrime;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: custom vs code snippet 
Csharp :: unity inspector sliders 
Csharp :: c# online code editor 
Csharp :: c# enum to string 
Csharp :: c# get first word of string 
Csharp :: call ienumerator unity 
Csharp :: get sites ip in C# 
Csharp :: c# loop array backwards 
Csharp :: unity destroy 
Csharp :: c# literals 
Csharp :: unity trigger not detecting collision 
Csharp :: c# optional parameters using 
Csharp :: web scraping dynamic content c# 
Csharp :: Nullable Types unity 
Csharp :: Responsive Bootstrap 4 Admin Dashboard icon cdn 
Csharp :: wpf scoll to on new item datagrtid 
Csharp :: git set origin url 
Html :: bootstrap col center content 
Html :: jquery ui cdn 
Html :: html link to call phone number 
Html :: Add Random Image from Web in html 
Html :: verbalna komunikacija 
Html :: a href email 
Html :: add space in html 
Html :: submit form on change 
Html :: how to add a logo icon in HTML 
Html :: font awesome cdn link 
Html :: how to create a button in html 
Html :: how to open in new page link html 
Html :: how to insert degree symbol in html 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =