using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch5_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int [] array = new int[100];
            int num = Convert.ToInt32(textBox1.Text);
            bool prime;
            array[0] = 2;
            int count = 1;
            for (int i = 3; i <= num; i++)
            {
                prime = true;
                for (int j = 0; j < count && prime; j++)
                    if (i % array[j] == 0)
                        prime = false;
                if (prime)
                {
                 array [count ++] = i;   
                }
            }
            //write numbers to listBox1
            for (int i = 0; i < count; i++)
                listBox1.Items .Add (array[i]);
        }
    }
}
