Is this homework time?

Breaking down your problem...

Get the factors. Compare the factors. The greatest common divisor is the
greatest common factor.



On 13 February 2010 11:40, newbiecoder <[email protected]> wrote:

> I am stuck at this coding...the method should return the Greatest
> Common Divisor (GCD) of two positive integers....For example the GCD
> of 6 and 25 is 1....the GCD of 8 and 12 is 4....
>
> The method I get from below is always a 1..
>
>
>  public static int GCD(int x, int y)
>       {
>
>            if(x==0)
>            {
>                return y;
>
>            }
>            else if (y == 0)
>            {
>                return x;
>
>            }
>
>
>
>            else if ( y==1)
>            {
>
>                return 1;
>
>
>            }
>
>            else
>            {
>                return  GCD(x, (y - 1));
>
>
>
>            }
>
>
>
>        }
>



-- 
Charles A. Lopez
[email protected]

Registered Microsoft Partner

New York City, NY

I'm running on Windows 7 Build 7100

Quality Software Works

Reply via email to