斐波那契数列(Fibonacci sequence),求1,1,2,3,5.….第30项数为多少?

斐波那契数列指的是这样一个数列 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 Sys­tem;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

name­space ConsoleApplication1
{
class Pro­gram
{

sta­t­ic void Main(string[] args)
{
Console.WriteLine(Return(30));
}

pub­lic sta­t­ic int Return(int i)
{
     if (i <= 0)
     {
        return 0;
     }
     else if (i == 1)
     {
        return 1;
     }
    else
     {
        return Return(i – 1) + Return(i – 2);
     }
}

}
}

为您推荐

发表评论

您的电子邮箱地址不会被公开。