I'm working on Project Euler number 5. I've not Googled, as that will typically lead to a SO with the answer. So, this is what I've got:
private int Euler5(int dividend, int divisor)
{
if (divisor < 21)
{
// if it equals zero, move to the next divisor
if (dividend % divisor == 0)
{
divisor++;
return Euler5(dividend, divisor);
}
else
{
dividend++;
return Euler5(dividend, 1); // move to the dividend
}
}
// oh hey, the divisor is above 20, so what's the dividend
return dividend;
}
In my mind, this makes sense. Yet VS2012 is giving me a StackOverFlowException suggesting I make sure I'm not in an infinite loop or using recursion. My question is, why is this an infinite loop? I've a feeling I'm missing something completely silly.
EDIT
Since people seem to keep posting them, I'll reiterate the fact that I didn't use Google for fear of stumbling on the answer. I don't want the answer to the problem. I only wanted to know why I was getting the exception.