Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Prime Number in C#

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 :: c# hashset 
Csharp :: set main camera unity 
Csharp :: c# listview 
Csharp :: get position of gameobject unity 
Csharp :: page refresh on button click in c# 
Csharp :: how to add a componet to a gameobject throgh code unity 
Csharp :: c# mapper.map 
Csharp :: c# loop backwards 
Csharp :: Create an array with random values c# 
Csharp :: how to delete file in c# 
Csharp :: how to find min of an array in c# 
Csharp :: unity 2d platformer movement script rigidbody 
Csharp :: why doesnt the if command work in C# 
Csharp :: How to make a drawer in unity 
Csharp :: how to mirror an image in vs forms 
Csharp :: razor: show editable list 
Csharp :: git set origin 
Html :: link js to html 
Html :: html include jquery 
Html :: favicon html link 
Html :: divi font awesome 
Html :: tabulation html 
Html :: no cache html 
Html :: js import web3 cdn 
Html :: laravel blade remove all html tags 
Html :: button center bootstrap 
Html :: font awesome icons 
Html :: multi-line comment xml 
Html :: how to link a local css file in html 
Html :: unmute html5 video jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =