用C#输出斐波拉契数列前30项
发布网友
发布时间:2023-09-24 02:29
我来回答
共2个回答
热心网友
时间:2023-10-06 00:50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fibonacci
{
class Program
{
static void Main(string[] args)
{
int x = 0, y = 1;
for (int j = 1; j <= 30; j++, y = x + y, x = y - x)
{
Console.Write(y + " ");
if (j % 5 == 0)
Console.WriteLine();
}
Console.Read();
}
}
}
热心网友
时间:2023-10-06 00:51
int[] arr;
arr=new int[30]{ 1, 1};
Console.WriteLine("1");
Console.WriteLine("1");
for (int i = 2; i <31; i++)
{
arr[i] =arr[i-1]+arr[i-2];
Console.WriteLine(arr[i]);
}