精选问答
1、求出Fibonacci(斐波那契)数列的前20项.Fibonacci(斐波那契)数列的规律是:前2项为0和1,其余各项为该项前2项之和,即0,1,1,2,3,5,8…….请将你解答本题所写的源程序粘贴到下面

2019-05-30

1、求出Fibonacci(斐波那契)数列的前20项.Fibonacci(斐波那契)数列的规律是:前2项为0和1,
其余各项为该项前2项之和,即0,1,1,2,3,5,8…….
请将你解答本题所写的源程序粘贴到下面
优质解答
c#的代码
class Program
{
static void Main(string[] args)
{
int[] a = new int[20];
a[0] = 0;
a[1] = 1;
for (int i = 2; i < 20; i++)
{
a[i] = a[i - 2] + a[i - 1];
}
for (int i = 0; i < 20; i++)
{
Console.Write(a[i]+" ");
}
Console.ReadKey();
}
}
c#的代码
class Program
{
static void Main(string[] args)
{
int[] a = new int[20];
a[0] = 0;
a[1] = 1;
for (int i = 2; i < 20; i++)
{
a[i] = a[i - 2] + a[i - 1];
}
for (int i = 0; i < 20; i++)
{
Console.Write(a[i]+" ");
}
Console.ReadKey();
}
}
相关问答