static void Main(string[] args) { int a = fib(7); Console.Write(a); Console.ReadKey(); } /// <summary> /// 非递归 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int NoRecursionFib(int n) { int[] arr = new int[n-1]; arr[0] = 1; arr[1]=1; if (n < 3) { return 1; } else { for (int i = 3; i < n; i++) { arr[i] = (arr[i - 1] + arr[i - 2]); } } return arr[n]; } /// <summary> /// 递归 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int fib(int n) { if (n <3) { return 1; } else { int a= fib(n - 1); int b= fib(n - 2); return a + b; } }