// WE KNOW THAT : lcm(x,y)= (x*y)/gcd(x,y)
package Recursion;
import java.util.Scanner;
public class RecLCM {
public static int lcm(int x,int y){
if(y==0) return x;
return lcm(y,x%y);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter x and y: ");
int x=sc.nextInt();
int y=sc.nextInt();
int ans=lcm(x,y);
System.out.println("LCM of "+x+" and "+y+" is: "+(x*y)/ans);
sc.close();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter