Difference between LCM and HCF of two numbers
Difference between LCM and HCF of two numbers
Two whole numbers N1 and N2 are passed as input. The program must print the difference between the LCM and HCF of these two numbers.
import java.util.Scanner;
public class Hello
{
public static void main(String args[])
{
int a, b, x, y, t, hcf, lcm;
Scanner scan = new Scanner(System.in);
x = scan.nextInt();
y = scan.nextInt();
a = x;
b = y;
while(b != 0)
{
t = b;
b = a%b;
a = t;
}
hcf = a;
lcm = (x*y)/hcf;
System.out.print(lcm-hcf);
}
}
Comments
Post a Comment