C# Program to Find LCM of two Numbers

In this C# program, we will take the input from the user and find LCM of two numbers.

C# program to Find LCM of two Numbers Code:

private static void Main(string[] args)
        {
            int n1, n2, max;

            Console.Write("Enter first number : ");
            n1 = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter second number : ");
            n2 = Convert.ToInt32(Console.ReadLine());

            max = (n1 > n2) ? n1 : n2;

            while (true)
            {
                if ((max % n1 == 0) && (max % n2 == 0))
                {
                    Console.WriteLine("LCM of {0} and {1} is {2}", n1, n2, max);
                    break;
                }
                ++max;
            }
            Console.ReadLine();
        }

C# program to Find LCM of two Numbers Output:

CSharp-program-to-Find-LCM-of-two-Numbers

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
3 + 2 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2022 CodingFusion
75 Important SQL Server queries you should know