### LCM of two numbers

You are given an inbuilt function GCD(int ,int) to generate GCD of two numbers.

public int GCD(int a, int b) { if (b==0) return a; return GCD(b,a%b); }

- Generate a function LCM(int , int) using above function.
- How will you use the same function to find LCM of

long LCM(int a, int b){

ReplyDeletereturn b*(a/GCD(a,b));

}

//let a[0..n-1] be an array

int r=a[0];

for(i=1;i<n;i++){

r=LCM(r,a[i]);

}

cout<<r;

nice solution....

ReplyDelete