c language - Fibonacci sequence

The Fibonacci  sequence, also known as the golden section sequence, was introduced by the mathematician Leonardo Fibonacci with the example of rabbit breeding, so it is also called " rabbit sequence ". is such a sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

Mathematically, the Fibonacci sequence is defined recursively as follows: F(0)=0, F(1)=1, F(n)=F(n - 1)+F(n - 2 ) (n ≥ 2, n ∈ N*);

Output a line of Fibonacci numbers in C language:

 The output is:

 Because the result of the last number in the Fibonacci sequence is the sum of the first two numbers, we can output the Fibonacci sequence through the loop statement in the C language. The values ​​of f1 and f2 are assigned to nextTerm, the value of f2 is assigned to f1, the value of nextTerm is assigned to f2, and finally the value of f1 is output.

 Since the Fibonacci sequence was introduced by mathematicians using rabbit breeding as an example, we can take a look at the following example:

 The rabbit reproduction in the title is exactly similar to the Fibonacci sequence, one pair in the first month, one pair in the second month, two pairs in the third month, three pairs in the fourth month, and five pairs in the fifth month.. ......

 As long as the output is less than the number of digits in the sequence where the number N is located, the result is as follows:

If there is an error in this article or there is a more streamlined code, welcome to correct and discuss

Guess you like

Origin blog.csdn.net/weixin_55305220/article/details/122194658