Write a program to get the Least Common Multiple (LCM) of an array of numbers.
Input (Integer Array) | Output(Integer) |
---|---|
{5, 10, 15, 30, 17} | 510 |
{24, 48, 64} | 192 |
{14, 34, 51, 28} | 1428 |
{18, 36} | 36 |
{84} | 84 |
class LCMOfArrayOfNumbers
{ public static void main(String s[])
{
int inputArray[] = {5, 10, 15, 30, 17};
System.out.println("The Least Common Multiple is : " + getLcmOfAllElements(inputArray));
}
public static int getLcmOfAllElements(int array[]) {
//Write code here to get the LCM of all the numbers in the array and return it.
}
}
Topic: Learn Arrays And Loops