C#斐波那契数列(递归算法)

namespace 递归算法

{

    class Program

    {

        static void Main(string[] args)

        {

        }

    }

      //斐波那契数列:1,1,2,3,5,8,13,21,34,55,……,

     //f(n) = f(n-1)+f(n-2);

     //f(5) = f(4)+f(3) = f(3)+f(2) + f(3) = f(2)+f(1) + f(2) + f(2)+f(1)   公式拆分

     //

     //

     //

    class Program

    {          

         static void Main(string[] agrs)

         {

             RecursiveClass recUrsice = new RecursiveClass();

             Console.WriteLine(recUrsice.RecUrsive(4));

             Console.ReadKey();

         }     

    }

    /// <summary>

    /// 递归类

    /// </summary>

    class RecursiveClass

    {

        public int RecUrsive(int index)

        {

            if (index < 3)//若index的值等于1或2,则返回1

            {

                return 1;

            }

            else

            {

                return RecUrsive(index – 1) + RecUrsive(index – 2);

            }

        }

    }

}

    原文作者:递归算法
    原文地址: https://blog.csdn.net/duanworld/article/details/68489796
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞