.NET 4.x Process is terminated due to StackOverflowException - C#
Формулировка задачи:
Закодировал простенький пример из книги по расчету факториала, при отладке выдает ошибку:
Process is terminated due to StackOverflowException
Текст C#:
Подскажите, в чем ошибка:
//вычисление факториала числа
using System;
class Factorial {
public int FactR(int n) {
int result;
result = FactR(n - 1) * n;
return result;
}
}
class Recursion {
static void Main(string [] args) {
int x;
x = 4;
Factorial obj = new Factorial();
Console.WriteLine("Факториал числа {0} равен {1}", x, obj.FactR(x));
}
}Решение задачи: «.NET 4.x Process is terminated due to StackOverflowException»
textual
Листинг программы
public int FactR(int n)
{
if (n <= 1) return 1;
return n * FactR(n-1);
}