Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Prime number Upto n

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 vscode snippet 
Csharp :: c# reflection 
Csharp :: index in foreach in c# 
Csharp :: draw table in console c# 
Csharp :: c# capitalize first letter of each word in a string 
Csharp :: bitwise and c# 
Csharp :: access audio source from gameobject unity 
Csharp :: c# loop back 
Csharp :: c# web scraping get images from specific url 
Csharp :: change object material unity 
Csharp :: get index of item unity 
Csharp :: how to convert c# string to pdf 
Csharp :: c# get regedit value 
Csharp :: unity add text to text field without deleting the old one 
Csharp :: c# web page show 2nd page of tiff on an image control 
Csharp :: flsa itextsharp 
Html :: html grundgerüst 
Html :: ssss 
Html :: html mailto 
Html :: fontawesome phone icon 
Html :: autoredirect html 
Html :: html disable enter submit 
Html :: how to set video speed html 
Html :: tailwind cdn 
Html :: gender selection in html 
Html :: meta redirect header 
Html :: fontawesome 
Html :: onclick button href 
Html :: no-gutter bootstrap 4 
Html :: font myriad pro html 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =