LCM

class LCM{
 public static void main(String ar[]){ 
  int a=8,b=12;
  double x=((a*b)/gcd(a,b));
  System.out.println("LCM  = "+x);
 }
 static int gcd(int a,int b)
 {
  if (a>=b&&a%b==0)
   return(b);
  else if(a<b)
   return(gcd(b,a));
  else
   return(gcd(b,a%b));
 }
}

No comments:

Popular Posts