Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20

my problem is the answer of this code i know its working but the answer is taking so long and the numbers still going

 class Program
    {
        static void Main(string[] args)
        {
            long Number = 1;
            for(int i = 1; i <= 20; i++)
            {
                if(Number%i != 0)
                {
                    i = 1;
                    Number++;
                }
                Console.WriteLine(Number);
            }
            Console.Read();
        }
    } ////// i want the console write the last number but i dont know what to do

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 static void Main(string[] args)
        {
            Console.WriteLine(problem().ToString());

}

    public static int problem()
            {
                int i =1;
                bool found = false;
                while (!found)
                {
                    i += 1;
                    bool isDividable = true;
                    for (int j = 1; j <= 20; j++)
                    {
                        if (i % j != 0)
                        {
                            isDividable = false;
                            break;
                        }
                    }
                    if (isDividable)
                    {
                        found = true;
                    }
                }
                return i;
            }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading