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());
}
}

2
Contributors
1
2
Views
11 Years
Discussion Span
Last Post by 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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.