Greatest Common Divisor/- The highest number that divides exactly into two or more numbers.It is the "greatest" thing for simplifying fractions!.
LCM= Product of two numbers / HCF(Highest Common Factor)
import java.util.*;
class hcfandlcm
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int h=1,m,n;
System.out.println("Enter 2 numbers");
m=sc.nextInt();
n=sc.nextInt();
int p=m*n;
for(int i=1;i<=p;i++)
{
if((m%i==0)&&(n%i==0))
{
h=i;
}
}
int l=p/h;
System.out.println("HCF="+h+" and LCM="+l);
}
}
LCM= Product of two numbers / HCF(Highest Common Factor)
import java.util.*;
class hcfandlcm
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int h=1,m,n;
System.out.println("Enter 2 numbers");
m=sc.nextInt();
n=sc.nextInt();
int p=m*n;
for(int i=1;i<=p;i++)
{
if((m%i==0)&&(n%i==0))
{
h=i;
}
}
int l=p/h;
System.out.println("HCF="+h+" and LCM="+l);
}
}