-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExTableau.cs
53 lines (51 loc) · 1.52 KB
/
ExTableau.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Logique;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exercices
{
public class ExTableau : iCommand
{
public string Name => "01_ExTableau";
public void Execute()
{
Console.Write("Tu veux connaître tous les nombres premiers jusqu'à quel nombre ? ");
int nb;
bool b = int.TryParse(Console.ReadLine(), out nb);
DateTime start = DateTime.Now;
bool test = false;
int nbPremier = 2;
List<int> list = new List<int>();
list.Add(nbPremier);
if (b && nb > 1)
{
while (nbPremier < nb)
{
nbPremier++;
test = false;
if (nbPremier % 2 != 0)
{
int sqrt = (int)Math.Sqrt(nbPremier);
for (int i = 3; i <= sqrt && !test; i += 2)
{
if (nbPremier % i == 0)
{
test = true;
}
}
if (!test)
{
list.Add(nbPremier);
}
}
}
foreach (int item in list)
{
Console.WriteLine(item);
}
}
}
}
}