Tuesday, December 19, 2017

Problem 5

    /*
    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
    What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
     */
    class Program
    {
        static void Main(string[] args)
        {
            bool divisible = false;
            int number = 1;
            while(divisible == false)
            {
                divisible = true;
                for(int i = 1; i<=20; i++)
                {
                    if((number%i) !=0  )
                    {
                        divisible = false;
                        break;
                    }
                }
                if(divisible==true)
                {
                    Console.WriteLine(number);
                    break;
                }
                else
                {
                    number++;
                }
            }
        }
    }

No comments:

Post a Comment