The
LCM can be gcd by dividing the product of two numbers by these two numbers. For example, the GCD of 12 and 9 is 3, then the two-digit LCM is calculated as 12*9/3, and the result of the calculation is LCM of the two numbers. The code is as follows:
private int Getzxgbs (params int[] parameters)
{
if (parameters.
Length = = 1)
return parameters[0];
List<int> resultlist=new list<int> ();
if (parameters. Length% 2 = 0)
{
for (int i = 0; i < parameters. Length; i=i+2)
{
int result=mingongbeishu (parameters[i],parameters[i+1]);
Resultlist.add (Result);
}
}
Else
{
for (int i = 0; i < parameters. Length; i = i + 2
{
int result = Mingongbeishu (Parameters[i], parameters[i + 1]);
Resultlist.add (Result);
}
Resultlist.add (parameters[parameters. Length-1]);
}
Return Getzxgbs (Resultlist.toarray ());
}
public int Mingongbeishu (int n1, int n2)
{
Int temp = Math.max (n1, N2);
N2 = Math.min (n1, N2); in//n2, the smallest of the two numbers in
N1 = Temp;//n1 hold the largest
int product = N1 * n2;//to find the product of two numbers
while (N2
!= 0
{
N1 = n1 > n2? n1:n2;//to make the number in N1 greater than the number in n2
int m = n1% N2;
N1 = n2;
N2 = m;
}
return (PRODUCT/N1);//LCM
}