Print Prime Numbers

            for (int n = 2; n < 100; n++)
            {
                int i = 0;
                for (int j = 2; j < n; j++)
                {
                    if ((n % j) == 0)
                    {
                        i = 1;
                    }
                }
                if (i == 0)
                {
                    lbltext.Text += Convert.ToString(n) + '.';
                }
            }

..................................................................................................

            for (int n = 2; n < 100; n++)
            {
                bool Prime = true;
                for (int j = 2; j < n; j++)
                {
                    if ((n % j) == 0)
                    {
                        Prime = false;
                        break;
                    }
                }
                if (Prime)
                {
                    lbltext.Text += Convert.ToString(n) + '.';
                }
            }

0 comments:

Post a Comment