我对课堂作业有疑问,我需要知道如何使用迭代返回第n个Fibonacci序列(不允许递归).
我需要一些关于如何做到这一点的提示,以便我能更好地理解我做错了什么.我在program.cs中输出到控制台,因此它在下面的代码中不存在.
// Q1)
//
// Return the Nth Fibonacci number in the sequence
//
// Input: uint n (which number to get)
// Output: The nth fibonacci number
//
public static UInt64 GetNthFibonacciNumber(uint n)
{
// Return the nth fibonacci number based on n.
if (n == 0 || n == 1)
{
return 1;
}
// The basic Fibonacci sequence is
// 1, 1, 2, 3, 5, 8, 13, 21, 34...
// f(0) = 1
// f(1) = …Run Code Online (Sandbox Code Playgroud)