I am trying to learn recursion and I am attempting to do factorial's via recursion instead of loops, but my program is causing "Process is terminated due to StackOverflowException
class RecursionFactorial
{
public static int n;
static void Main(string[] args)
{
string input;
Console.WriteLine("Please enter a number to work out the factorial");
input = Console.ReadLine();
bool test = int.TryParse(input, out n);
fact(n);
}
public static int fact(int y)
{
int count = n;
if (y <= 1)
{
Console.WriteLine(y);
}
else
{
count = (count * y);
Console.WriteLine(count);
fact(y - 1);
}
}
}