/// <summary> /// 递归方式 : 思路简单但效率比循环方式低,递归次数越多,性能越低 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Fn(int n) { if (n <= 2) { return 1; } checked // 检查算术溢出 { return Fn(n - 1) + Fn(n - 2); } } /// <summary> /// 循环方式 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int FnFor(int n) { int first = 1; int second = 1; for (int i = 3; i <= n; i++) { checked { second = first + (first = second); } } return second; }