斐波那契数列

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........

很简单的实现代码:

        /// <summary>
        /// 斐波那契数列
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static int Foo(int i)
        {
            if (i <= 0)
            {
                return 1;
            }
            else if (i > 0 && i <= 2)
            {
                return 1;
            }
            else
            {
                return Foo(i - 1) + Foo(i - 2);
            }
        }

 

posted on 2017-03-23 07:13  Jade_K  阅读(113)  评论(0编辑  收藏  举报

导航