WAP TO FIND HCF AND LCM IN JAVA
import java.util.*;
class hcf
{
public static void main(String args[])
{
int a,b,h=1,l,min,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the a and b");
a=sc.nextInt();
b=sc.nextInt();
for(i=1;i<=a*b && i<=b*a;i++)
{
if(a%i==0 && b%i==0)
{
h=i;
}
}
l=(a*b)/h;
System.out.println("Hcf="+h);
System.out.println("Lcm="+l);
}
}
class hcf
{
public static void main(String args[])
{
int a,b,h=1,l,min,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the a and b");
a=sc.nextInt();
b=sc.nextInt();
for(i=1;i<=a*b && i<=b*a;i++)
{
if(a%i==0 && b%i==0)
{
h=i;
}
}
l=(a*b)/h;
System.out.println("Hcf="+h);
System.out.println("Lcm="+l);
}
}
Comments
Post a Comment