write a Java Program which will input two numbers and find HCF and LCM
Answers
Answered by
8
//Finding HCF and LCM
public class HCF_LCM
{
public void comp(int n, int m)
{
int low=0, p=n*m, hcf=0, lcm=0;
if(n<m)
low=n;
else
low=m;
for(int i=low; i>=1;i--)
{
if(n%i==0 && m%i==0)
{
hcf=i;
break;
}
}
lcm=p/hcf;
System.out.println("Numbers are:"+n+""+m);
System.out.println("LCM=" +lcm);
System.out.println("HCF=" +hcf);
}
}
Remember:- Product of two numbers is equal to the product of LCM and HCF.
public class HCF_LCM
{
public void comp(int n, int m)
{
int low=0, p=n*m, hcf=0, lcm=0;
if(n<m)
low=n;
else
low=m;
for(int i=low; i>=1;i--)
{
if(n%i==0 && m%i==0)
{
hcf=i;
break;
}
}
lcm=p/hcf;
System.out.println("Numbers are:"+n+""+m);
System.out.println("LCM=" +lcm);
System.out.println("HCF=" +hcf);
}
}
Remember:- Product of two numbers is equal to the product of LCM and HCF.
Similar questions
Social Sciences,
7 months ago
Accountancy,
7 months ago
Math,
7 months ago
Chemistry,
1 year ago
Physics,
1 year ago
Math,
1 year ago
Social Sciences,
1 year ago