小编use*_*351的帖子

返回第N个Fibonacci数序列?

我对课堂作业有疑问,我需要知道如何使用迭代返回第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)

c# iteration fibonacci

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

fibonacci ×1

iteration ×1