Tag: fibonacci

帮助LINQ表达式

如何编写一个LINQ表达式(首选方法调用语法),它给出一个位于特定范围内的斐波那契数字列表,比如1到1000?

返回第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) { […]

平行斐波纳契数计算器

我正在使用任务并行库(TPL)来计算斐波纳契数。 计划如下: public static int Fib(int n) { if (n <= 1) { return n; } Task task = Task.Factory.StartNew(() => Fib(n – 1)); var p = Fib(n – 2); return task.Result + p; } public static void Main(string[] args) { Stopwatch watch = new Stopwatch(); watch.Start(); Console.WriteLine(“Answer: ” + Fib(44)); watch.Stop(); Console.WriteLine(“Time: ” + […]