Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

lcm of list of number

    // 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;
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to make button in asp.net to go to other page 
Csharp :: hcf of numbers 
Csharp :: c# open file for reading and writing 
Csharp :: json property c# 
Csharp :: c# print decimal with zero at the end 
Csharp :: how to add headers to scripts in unity 
Csharp :: c# how to check if a array bool is all true 
Csharp :: check two lists are equal c# 
Csharp :: unity text color 
Csharp :: convert object to httpcontent c# 
Csharp :: multiplication of long number 
Csharp :: c# copy files from one folder to another 
Csharp :: list to ienumerable c# 
Csharp :: how to set foreground from code wpf 
Csharp :: c# today without time 
Csharp :: wpf get function name 
Csharp :: random in f# 
Csharp :: c# close form 
Csharp :: c# #region #endregion 
Csharp :: unity banner Ad position 
Csharp :: default parameter c# 
Csharp :: how to get the size an array in unity 
Csharp :: Get enum value from string or int 
Csharp :: vb.net remove last comma from string 
Csharp :: replace multiple characters in string c# 
Csharp :: initialize a char array java 
Csharp :: if list does not contain then add c# 
Csharp :: c# get witdh of matrix 
Csharp :: Commenting on C# 
Csharp :: c# loop string 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =