|
namespace Recursion
{
//Greatest Common Divisor(GCD) Example
class GCD
{
static int depth;
public GCD() { }
public int CalculateGCD(int x,int y)
{
depth++;
if (depth == 1)
{
if (x < y || y < 0)
return -1;
}
if (y == 0 )
{
return x;
}
else
{
//Reduced to last limit problem
return CalculateGCD(y, x % y);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Working as Senior Developer in US based MNC. Interested in R&D, writing/reading techinical articles, sci-fi movies, playing synthesizer.