i want to find the lcm ,cant it be found without using gcd?
class Gcd
{ int a,b;
Gcd(int a,int b )
{
this.b=b;
this.a=a;
}

int gcd( int a,int b)
{
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
return a;
}
}
int lcm()
{
int l;
if(a<b)
l=(a*b)/gcd(a,b);
else
l=(a*b)/gcd(a,b);
return l;
}
public static void main(String[] args)
{
Gcd g =new Gcd(10,5);
//g.gcd()
System.out.println("gcd is"+g.lcm());
}
}

Member Avatar for iamthwee
class Gcd
{
    int a, b;
    Gcd ( int a, int b )
    {
        this.b = b;
        this.a = a;
    }

    int gcd ( int a, int b )
    {
        while ( a != b )
        {
            if ( a > b )
                a = a - b;
            else
                b = b - a;
            return a;
        }
    }
    int lcm()
    {
        int l;
        if ( a < b )
            l = ( a * b ) / gcd ( a, b );
        else
            l = ( a * b ) / gcd ( a, b );
        return l;
    }
    public static void main ( String[] args )
    {
        Gcd g = new Gcd ( 10, 5 );
       //g.gcd()
        System.out.println ( "gcd is" + g.lcm() );
    }
}

http://en.wikipedia.org/wiki/Least_common_multiple

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.