[code lang=”csharp”]
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int n = 0;
Console.Write("Podaj liczbe: ");
n = Convert.ToInt32(Console.ReadLine());
bool[] tab = new bool[n + 1];
for (int i = 2; i * i <= n; i++)
{</pre>
<!–more–>
<pre> if (tab[i] == true)
{
continue;
}
for (int j = 2 * i; j <= n; j += i)
{
tab[j] = true;
}
}
Console.WriteLine("Liczby pierwsze z zakresu [1," + n + "]: ");
for (int i = 2; i <= n; i++)
{
if (tab[i] == false)
{
Console.Write(i + " ");
}
}
Console.ReadKey();
}
}
}</pre>
[/code]
pilne na wczoraj!!!
Liczba pierwsza – liczba naturalna, która ma dokładnie dwa dzielniki naturalne: jedynkę i siebie samą, np.
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, itp.