码迷,mamicode.com
首页 > 其他好文 > 详细

菲波那切数列

时间:2016-10-23 23:51:28      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:string   family   style   str   else   void   输入   justify   ...   

一个数组: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);

            }

        }

菲波那切数列

标签:string   family   style   str   else   void   输入   justify   ...   

原文地址:http://www.cnblogs.com/wangxlei/p/5991322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!