Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Generate Prime Numbers

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 :: how to get image from resource folder in c# 
Csharp :: C# listview as listbox 
Csharp :: polymorphism in c# 
Csharp :: how to create a point c# 
Csharp :: randon C# 
Csharp :: .net 6 get appsettings value 
Csharp :: shallow copy vs deep copy c# 
Csharp :: unity pause 
Csharp :: swagger skip endpoint .net core 
Csharp :: appsettings in console application c# 
Csharp :: c sharp or operator in if statement 
Csharp :: belgiumcampus 
Csharp :: unity public script 
Csharp :: hydrogen fuels 
Csharp :: how to move balance from one card to another target 
Csharp :: forces the user to enter his password before submitting the form asp.net core 
Csharp :: git change remote origin 
Html :: calling javascript file in html 
Html :: copyright footer html code 
Html :: open phone from anchor tag 
Html :: include script in html 
Html :: tab space in html 
Html :: how to import taglib 
Html :: remove underline html 
Html :: html href tel 
Html :: <noscript<p title="</noscript<img src=x onerror=alert(1)" 
Html :: font awesome cdn 
Html :: abrir pdf con html 
Html :: html click to call 
Html :: how to make form not reload page 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =