C#递归实现:斐波那契数列
//斐波那契数列 指的是这样一个数列:1,1,2,3,5,8,13,21,34……
public static int Foo(int i)
{
if (i < 3)
{
return 1;
}
else
{
return Foo(i - 1) + Foo(i - 2);
}
}
static void Main(string[] args)
{
Console.WriteLine(Foo(8));
}
public static int Foo(int i)
{
if (i < 3)
{
return 1;
}
else
{
return Foo(i - 1) + Foo(i - 2);
}
}
static void Main(string[] args)
{
Console.WriteLine(Foo(8));
}
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利
This posting is provided "AS IS" with no warranties, and confers no rights.
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号