Thursday, November 18, 2010

program for display lcm of n numbers in java[ different way]

import java.io.*;
class lcm_f_n_nos
{
    public static void meth()throws IOException
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,no1,no2,lcm=1,i;
System.out.println("enter no of numbers");
 n=Integer.parseInt(br.readLine());
while(n>0)
{
no1=lcm;
lcm=1;
System.out.println("enter nunbers");
no2=Integer.parseInt(br.readLine());
for(i=2;i<=(no1*no2);i++)
{
if((no1%i==0)&&(no2%i==0))
{
lcm=lcm*i;
no1=no1/i;
no2=no2/i;
i=i-1;
    }
}
lcm=lcm*no1*no2;
    n=n-1;
}
System.out.println("LCM:"+lcm);
    }
}

1 comment:

Anonymous said...

hello dear, there are some pathetic mistakes in your code! pls rectify them before you upload them!