首页 > 代码库 > 菲波那切数列

菲波那切数列

一个数组:1,1,2,3,5,8,13,21...+m;

static void Main(string[] args)

        {

            Console.Write("输入想求的斐波那契数列项数:");

            int n = Convert.ToInt32(Console.ReadLine());

            //递归实现

 

            Console.WriteLine("斐波那契数列数列递归算出的第{0}项为:{1}", n, Calculate(n));

        }

        static int Calculate(int n)

        {

            if (n <= 1)

            {

                return n;

            }

            else

            {

                return Calculate(n - 1) + Calculate(n - 2);

            }

        }

菲波那切数列