斐波那契数列(Fibonacci Number)从数学的角度是以递归的方法定义的:

  • \(F_0 = 0\)
  • \(F_1 = 1\)
  • \(F_n = F_{n-1} + F_{n-2}\) (\(n \geq 2\))

C# 的递归算法实现如下:

/// <summary>
/// 返回指定序数的 Fibonacci number
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public int FibonacciNumber(int index)
{
if (index == 0)
{
return 0;
}
else if (index == 1)
{
return 1;
}
else
{
return FibonacciNumber(index - 1) + FibonacciNumber(index - 2);
}
}

Algorithms - Fibonacci Number的更多相关文章

  1. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

  2. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  3. [UCSD白板题 ]Small Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  4. (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)

    根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...

  5. 求四百万以内Fibonacci(number)数列偶数结果的总和

    又对啦...开心~~~~ 只是代码可能不符合PEP标准什么的... Each new term in the Fibonacci sequence is generated by adding the ...

  6. Fibonacci number

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  7. 【LEETCODE】44、509. Fibonacci Number

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  8. 【leetcode】509. Fibonacci Number

    problem 509. Fibonacci Number solution1: 递归调用 class Solution { public: int fib(int N) { ) return N; ...

  9. fibonacci number & fibonacci sequence

    fibonacci number & fibonacci sequence https://www.mathsisfun.com/numbers/fibonacci-sequence.html ...

随机推荐

  1. CommonJS、AMD与CMD

    自从有了模块,我们可以更方便地使用别人的代码,想要什么功能,就加载什么模块.但是,这样做有一个前提,那就是大家必须以同样的方式编写模块,否则你有你的写法,我有我的写法,岂不是乱了套! 于是下面三个模块 ...

  2. 【海量之道】海量之道之SET模型

    本文介绍了set模型. 一 提供海量服务时面对的场景 场景1:如何令黄村机房的TWS机器访问黄村机房的APP服务,避免TWS跨机房调用永丰机房的APP机器? 场景2:DB和Redis如何实现快慢分离, ...

  3. HTML5学习记录——3

    HTML媒体 1.HTML多媒体 视频格式 .avi    微软开发 .wmv  微软开发 .mpg  .mpeg .mov 苹果公司开发 .rm  .ram  允许低带宽的视频流 .swf  .fl ...

  4. POJ 2421 Constructing Roads(Kruskal算法)

    题意:给出n个村庄之间的距离,再给出已经连通起来了的村庄.求把所有的村庄都连通要修路的长度的最小值. 思路:Kruskal算法 课本代码: //Kruskal算法 #include<iostre ...

  5. freeMarker(十二)——模板语言补充知识

    学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.特殊变量参考 特殊变量是由FreeMarker引擎自己定义的变量. ...

  6. CodeForces - 1017F. The Neutral Zone (数学+Bitset存素数+素数筛优化)

    Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And ...

  7. PRVF-0002 : could not retrieve local node name

    安装 oracle 的时候,./runInstaller 启动报错  PRVF-0002 : could not retrieve local node name 碰到这个错误是因为 OUT试图对你主 ...

  8. ECMAScript中面向对象的程序设计思想总结

    <JavaScript高级程序设计>Chapter6笔记 1.ECMAScript内部值属性:数据属性和访问器属性 1)数据属性 数据属性的4个特性: configurable:表示能否通 ...

  9. mysql du-master配置

    db-server1 my.cnf log_bin = mysql-binbinlog_format = mixedserver_id = 1 read-only = 0#binlog-do-db = ...

  10. Java中读取输入方式的性能比较

    程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值的现成函数!Java没有提供这样的函数也不代表遇到这 ...