用C# for函数做 1 1 2 3 5 8 13 前两个数相加等于第三个数

1个回答

  • static void Main(string[] args)

    {

    int[] aa;

    int tmp = 0;

    int i = 0;

    int n = 0;

    aa = new int[2];

    aa[0] = 1;

    aa[1] = 1;

    n = Convert.ToInt32(Console.ReadLine());

    for (i = 0; i < n; i++)

    {

    if (2 > i)

    {

    Console.Write("{0} ",aa[i]);

    }

    else

    {

    tmp = aa[0] + aa[1];

    aa[0] = aa[1];

    aa[1] = tmp;

    Console.Write("{0} ",tmp);

    }

    }

    Console.WriteLine();

    }