c#斐波那契数列

╄→гoц情女王★ 提交于 2020-01-25 18:01:12

用控制台写的计算斐波那契数列

新建一个类

namespace 斐波那契数列
{
    class student
    {
        public int shy(int index)
        {
            if (index<1)
            {
                return 0;
            }
            else if(index==1||index==2)
            {
                return 1;
            }
            else
            {
                return shy(index - 1) + shy(index-2);
            }
        }
    }
}

主窗体

namespace 斐波那契数列
{
    class Program
    {
        static void Main(string[] args)
        {
            student stu = new student();
            Console.WriteLine(stu.shy(80));
            Console.ReadLine();
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!