斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368.….…
这个数列从第3项开始,每一项都等于前两项之和。
通项公式
(如上,又称为“比内公式”,是用无理数表示有理数的一个范例。)
注:此时a1=1,a2=1,an=an‑1+an‑2(n>=3,n∈N*)
C#程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Return(30));
}
public static int Return(int i)
{
if (i <= 0)
{
return 0;
}
else if (i == 1)
{
return 1;
}
else
{
return Return(i – 1) + Return(i – 2);
}
}
}
}