【C#】Fibonacci

简单来说~费氏数列从0 and 1开始~

后面的每一个数~ 都是前两数相加得来~

例如,0,1,1,2,3,5,8.....


学习目标: Fibonacci的概念及实务

学习难度: ☆☆☆


using System;namespace ConsoleApp1{    class MainProgram    {        static int Fibonacci(int number)        {            if (number == 0)            {                return 0;            }            if (number == 1)            {                return 1;            }            else            {                return Fibonacci(number - 1) + Fibonacci(number - 2);            }        }        static void Main()        {            try            {                int Number = int.Parse(Console.ReadLine());                for (int i = 1; i <= Number; i++)                {                    Console.WriteLine(Fibonacci(i).ToString());                }            }            catch (Exception ex)            {                Main();            }        }    }}

参考资料:

https://zh.wikipedia.org/wiki/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章