One more post

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmallestFactor
{
    class Program
    {
        static void Main(string[] args)
        {           
            Console.WriteLine("Enter the minimum number : ");
            int minnumber = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the maximum number : ");
            int maxnumber = Convert.ToInt32(Console.ReadLine());
           
            if ((minnumber < 1) || (maxnumber < 1) || (maxnumber <= minnumber))
            {
                Console.WriteLine(@"Either Minimum is less than 1 Or Maximum is less than 1 Or Maximum is less than Minimum. Exiting Application.");
                Console.ReadKey();
                return;
            }
           
            int i = 0;
            int numseq = 0;
            for (numseq = minnumber; numseq <= maxnumber; numseq++)
            {
                int counter = 0;
                for (i = 1; i <= numseq; i++)
                {
                    if (numseq == 1)
                        break;

                    if (numseq % i == 0)
                    {
                        {
                            counter = counter + 1;
                            if (counter == 2)
                            {
                                break;
                            }
                        }
                    }
                }
                Console.WriteLine("The smallest factor for {0} is {1}", numseq, i);
            }
            Console.ReadKey();
        }
    }
}

/* Select the smallest and biggest numbers. If smallest or biggest is less than 1 or if max is less than min, then abort. Whenever the modulo is equal to 0 , increment the counter. If counter = 2, then exit and type in the value of i*/


No comments:

Post a Comment