本帖最后由 gaoda871010 于 2010-05-31 08:53:44 编辑

解决方案 »

  1.   


    static void GetNumber(int ipos)
         {
              Int64[] list = new Int64[ipos];
              list[0] = 1;
             list[1] = 1;
             for (int i = 2; i < ipos; i++)
              {
                    list[i] = list[i - 1] + list[i - 2];
              }          Console.WriteLine(list[ipos-1].ToString());
           }
      

  2.   


    public static int GetFibonacciNum(int i)
            {
                if (i < 0) return -1;
                if (i < 3) return 1;
                int temp = 2;
                int head = 1;
                int end = 1;
                while (temp < i)
                {
                    head += end;
                    head ^= end;
                    end ^= head;
                    head ^= end;
                    temp++;
                }
                return end;
            }
      

  3.   

    看错题了 再发遍public class Test
        {
            public static void Main(string[] args)
            {
                int[] arr = GetFibonacciNum(20);
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.WriteLine("Fibonacci数列第 {0} 个数为: {1}", i + 1, arr[i]);
                }            Console.ReadLine();
            }        public static int[] GetFibonacciNum(int nth)
            {
                int[] fibonacciArr = new int[nth];
                fibonacciArr[0] = 1;
                fibonacciArr[1] = 1;
                for (int i = 2; i < nth; i++)
                {
                    fibonacciArr[i] = fibonacciArr[i - 1] + fibonacciArr[i - 2];
                }
                return fibonacciArr;
            }
        }
      

  4.   

                int[] List = new int[20];
                for (int i = 0; i < List.Length; i++)
                {
                    if (i < 2)
                    {
                        List[i] = 1;
                    }
                    else
                    {
                        List[i] = List[i - 1] + List[i - 2];
                    }
                }