JS algorithm Set (ii) JavaScript implements Fibonacci sequence (rabbit sequence)

Source: Internet
Author: User

JS algorithm set (ii) Fibonacci sequence

Last time I shared with you the idea of how to do the number of daffodils, and extended it to the algorithm of the self-power number, this time, we will study the Fibonacci sequence to deepen our understanding of the cycle.

JavaScript implements the Fibonacci sequence① to use JavaScript to implement the Fibonacci sequence, we first need to understand what the Fibonacci sequence is, the Fibonacci sequence (Fibonacci sequence), also known as the Golden Section, the mathematician Leonardo's Fibonacci (Leonardoda    Fibonacci) is introduced as an example of rabbit reproduction, which is also known as the "Rabbit series", referring to such a series: 1, 1, 2, 3, 5, 8, 13, 21, 、...... ② learned what Fibonacci numbers are and we're going to start analyzing how to do it. Through the study of law, the law, such as: ③ get the law, we have to study how to use code to achieve, specifically how to implement see Code, and comments:

    

1<script>2         3         varA = 1;//Declare the first number is 14         varb = 1;//declares a second number of 15         varC//declare an intermediate variable C6document.write (A + "<br>" +b+ "<br>");//print top two known quantity7          for(vari = 3; I <= 10; i++) {//The first two are known, starting from the third cycle, 10 is the number of printed sequence content, can be self-testing8c = a + B;//each number equals two of its front and9document.write (c+ "<br>");//print number I, take i=3; for example: c=2TenA = b;//when the next number is printed, A and B are changed, and the value of B gives the value of A,a=1,c to b,b=2; Oneb = C;//A and B are pushed backwards to perform the next operation . A         } -          -</script>

   


this time Here's the share .

Thank you for watching.

feel good Please praise

I hope we can inspire you .

There are better ways or different opinions please contact me in the message area .

  

JS algorithm Set (ii) JavaScript implements Fibonacci sequence (rabbit sequence)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.