Wednesday, January 16, 2008

HCF and LCM of 2 numbers

import java.io.*;
class lowhigh
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a,b,c,i,j,t,k,p,lcm,hcf=1;
System.out.println(" Enter any 3 number ");
a = Integer.parseInt(br.readLine());
b = Integer.parseInt(br.readLine());
c = Integer.parseInt(br.readLine());
p = a*b*c;
for(i=1;i<=p;i++)
{
j = a%i;
t = b%i;
k = c%i;
if(j==0&&t==0&&k==0)
{
hcf = i;
}
}
lcm = p/hcf;
System.out.println(" the lcm is " + lcm);
System.out.println(" the hcf is " + hcf);
}
}

2 comments:

Sidhartha said...

rocking boss, it helped me a lot!!!

Unknown said...

Thanks gi,It's great :)