namespace 递归算法
{
class Program
{
static void Main(string[] args)
{
}
}
//斐波那契数列:1,1,2,3,5,8,13,21,34,55,……,
//f(n) = f(n-1)+f(n-2);
//f(5) = f(4)+f(3) = f(3)+f(2) + f(3) = f(2)+f(1) + f(2) + f(2)+f(1) 公式拆分
//
//
//
class Program
{
static void Main(string[] agrs)
{
RecursiveClass recUrsice = new RecursiveClass();
Console.WriteLine(recUrsice.RecUrsive(4));
Console.ReadKey();
}
}
/// <summary>
/// 递归类
/// </summary>
class RecursiveClass
{
public int RecUrsive(int index)
{
if (index < 3)//若index的值等于1或2,则返回1
{
return 1;
}
else
{
return RecUrsive(index – 1) + RecUrsive(index – 2);
}
}
}
}