Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            nombreLimite = Convert.ToInt32(textBox1.Text);
            bool[] nombresPremiers = null;
            listBox1.Items.Clear();
            listBox1.MultiColumn = true;
            Eratostene era = new Eratostene(nombreLimite);

            try
            {
                nombresPremiers = era.crible();
                for (int x = 1; x <= nombreLimite; x++)
                {
                    listBox1.Items.Add((nombresPremiers[x] == true) ? x.ToString() : "X");
                    if (nombresPremiers[x] == true)
                    {
                        listBox1.SetSelected(x - 1, true);
                    }
                }
            }
            catch (Exception ex)
            {
                listBox1.Items.Add(ex.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            bool[] nombresPremiers = null;


            Console.Write("Nombres premiers jusqu' à  combien : \n");
            int taille = Convert.ToInt32(Console.ReadLine());
            // nombresPremiers = new bool[taille+1];
            Eratostene era = new Eratostene(taille);

            try
            {
                nombresPremiers = era.crible();
                Console.WriteLine("Les nombres premiers inférieurs ou égales à {0} sont :", taille);
                for (int j = 0; j < nombresPremiers.Length; j++)
                {
                    Console.Write((nombresPremiers[j] == true) ? j + "\t" : "");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }



            Console.Read();
        }
Esempio n. 3
0
 public EratosteneForm()
 {
     InitializeComponent();
     era = new Eratostene();
 }