标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication5 { class Program { public int shuzi(int i) { int sum = 0; if (i <= 0) { sum = 0; } else if (i == 1 || i == 2) { sum = 1; } else { sum = shuzi(i - 1) + shuzi(i - 2); } return sum; } static void Main(string[] args) { Program pg = new Program(); Console.Write("请输入数字:"); int shuzi = int.Parse(Console.ReadLine()); int zongshu = pg.shuzi(shuzi); Console.Write("第" + shuzi + "个数的数字是:" + zongshu); Console.ReadLine(); } } }
一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。
标签:
原文地址:http://www.cnblogs.com/zhuxu/p/5199906.html