Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Lcm of numbers

    // call this function
    public static int LCM(List<int> input) 
    {
         int result = input[0];
         for (int i = 1; i < input.Count; i++) 
         {
            result = lcm(result, input[i]);
         }
         return result;
    }

    private static int LCM(int a, int b) 
    {
        return a * (b / gcd(a, b));
    }
	private static int gcd(int a, int b) 
    {
        while (b > 0) 
        {
            int temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }

    private static int gcd(List<int> input) 
    {
        int result = input[0];
        for (int i = 1; i < input.Count; i++) 
        {
            result = gcd(result, input[i]);
        }
        return result;
    }
 
PREVIOUS NEXT
Tagged: #Lcm #numbers
ADD COMMENT
Topic
Name
4+2 =