program for prime number

I know it is Xmass, I shall be generous.
Seek and thou shalt find!

Simple demo for Range of Prime Numbers:

static void Main(string[] args)
        {
            List<int> PrimeNumbers = GeneratePrimeNumbers(1, 10);

            foreach (int i in PrimeNumbers)
                System.Diagnostics.Debug.WriteLine(i);
        }

        public static List<int> GeneratePrimeNumbers(int from, int to)
        {
            List<int> numbers = new List<int>();
            int num;
            int i;
            int factor;
            bool isprime;
            if (from == 1) { numbers.Add(from); from++; }
            for (num = from; num < to; num++)
            {
                isprime = true;
                factor = 0;
                // see if num is evenly divisible 
                for (i = 2; i <= num / 2; i++)
                {
                    if ((num % i) == 0)
                    {
                        // num is evenly divisible -- not prime 
                        isprime = false;
                        factor = i;
                        from++;
                    }
                }

                if (isprime)
                  numbers.Add(num); 
            }
            return numbers;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.