using System; class EratostenovoSito { static void Main() { int N, i, k; bool[] Precrtan; Console.Write("Unesite broj (najmanje 5) -> "); N = int.Parse(Console.ReadLine()); if(N <= 5) { Console.WriteLine("Broj nije >= 5"); } else { // trebaju nam kucice sa indeksima 2, 3, ..., N // zato zauzimamo N + 1 mesta; // kucice sa indeksima 0 i 1 necemo koristiti Precrtan = new bool[N + 1]; for(k = 2; k <= N; k++) { Precrtan[k] = false; } for(k = 2; k <= (int)Math.Sqrt(N); k++) { if(!Precrtan[k]) { // precrtavanje umnozaka for(i = 2 * k; i <= N; i += k) { Precrtan[i] = true; } } } Console.WriteLine("Prosti brojevi su:"); for(k = 2; k <= N; k++) { if(!Precrtan[k]) { Console.Write("{0} ", k); } } Console.WriteLine(); } } }