using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); if (n <= 0) { Console.WriteLine("必须大于0"); return; } if (n == 1) //时刻注意边界值!!! { Console.WriteLine("1"); return; } int[] data = new int[n]; data[0] = 1; data[1] = 1; for (int i = 2; i < n; i++) { data[i] = data[i - 1] + data[i - 2]; } Console.WriteLine(data[n - 1]); Console.ReadLine(); } } }
一个数组:1,1,2,3,5,8,13,21...+m,求第30位数是多少?用递归实现;(常考!!!)
原文:http://www.cnblogs.com/hanke123/p/5215268.html