Example #1
0
        private void btnGener_Click(object sender, EventArgs e)
        {
            try
            {
                int limit = Convert.ToInt32(tbZakres.Text);
                limit = limit < 2 || limit > 100000 ? 2000 : limit;
                _pn   = new PrimaryNumbers(limit);
                List <int>    primes = _pn.GetNumbers();
                StringBuilder sb     = new StringBuilder();
                sb.Append("Zbiór liczb pierwszych:" + Environment.NewLine);
                foreach (int prime in primes)
                {
                    sb.Append(prime + " ");
                }

                wynik.Text = sb.ToString();
            }
            catch (OverflowException ex)
            {
                MessageBox.Show("Błąd danych!!: " + ex.Message);
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Błąd danych!!: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Inny błąd: " + ex.Message);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            #region MyRegion
            //Console.Write("Podaj a: ");
            //int a = int.Parse(Console.ReadLine());
            //Console.Write("Podaj b: ");
            //int b = int.Parse(Console.ReadLine());
            //Console.WriteLine(a+" + "+b+" = "+(a+b));
            //Console.Write("Podaj swoje imie: ");
            //string imie = Console.ReadLine();
            //Console.Write("Podaj swoje nazwisko: ");
            //string nazwisko = Console.ReadLine();
            //Console.WriteLine("Witaj {0} {1} "
            //                  +DateTime.Now.Date.ToLongDateString(),imie,nazwisko);
            #endregion


            Console.WriteLine("======= LICZBY PIERWSZE ================");
            Console.Write("Podaj do jakiej liczby szukac (wiecej niz 1): ");
            int            limit = int.Parse(Console.ReadLine());
            PrimaryNumbers ps    = new PrimaryNumbers(limit);
            Parzyste       pp    = new Parzyste(limit);
            Console.WriteLine("Liczby pierwsze:");
            foreach (int number in ps.GetNumbers())
            {
                Console.Write(number + " ");
            }
            Console.WriteLine("\nLiczby parzyste:");
            foreach (int number in pp.GetParzyste())
            {
                Console.Write(number + " ");
            }
            Console.ReadKey();
        }
Example #3
0
        public void IsPrimary()
        {
            var        primary = new PrimaryNumbers(21);
            List <int> numbers = primary.GetNumbers();

            Assert.AreEqual(true, primary.isPrimary(19));
            Assert.AreEqual(false, primary.isPrimary(21));
        }
Example #4
0
        public void CanGet2()
        {
            var        primary = new PrimaryNumbers(2);
            List <int> numbers = primary.GetNumbers();

            Assert.AreEqual(1, numbers.Count);
            Assert.AreEqual(2, numbers[0]);
        }
Example #5
0
        public void CanGetFirstTo10()
        {
            var        primary  = new PrimaryNumbers(10);
            List <int> numbers  = primary.GetNumbers();
            List <int> expected = new List <int>()
            {
                2, 3, 5, 7
            };

            Assert.AreEqual(4, numbers.Count);
            Assert.AreEqual(7, numbers[3]);
        }
Example #6
0
        public ActionResult Index(Primal primal)
        {
            if (ModelState.IsValid)
            {
                int liczba    = primal.Liczba;
                int ilwierszy = (liczba / 20) + 1;

                PrimaryNumbers pn = new PrimaryNumbers(liczba);
                StringBuilder  sb = new StringBuilder();
                foreach (var item in pn.GetNumbers())
                {
                    sb.Append(item + " ");
                }

                ViewBag.primary = pn.GetNumbers();
                ViewBag.liczby  = sb.ToString();
                ViewBag.rows    = ilwierszy;
                return(View());
            }
            else
            {
                return(View(primal));
            }
        }