代码
//斐波那契数列
public class FibonacciSequence
{
/// <summary>
/// 这是一个计算斐波那契数列方法。
/// </summary>
/// <param name="index">第几个斐波那契数列</param>
/// <returns>第index个斐波那契数列值</returns>
public static int Run(int index)
{
int intResult = 0;
List<int> list = [0, 1];
for (int m = 1; m < index; m++)
{
intResult = list[^2] + list[^1];
list.Add(intResult);
list.RemoveAt(0);
}
Console.WriteLine($"index={index},value={intResult}");
return intResult;
}
}
计算第20个斐波那契数列
标签:index,数列,C#,list,斐波,intResult,那契 From: https://www.cnblogs.com/huiy/p/18508843index=20,value=6765;