C language typical example 4 - Fibonacci sequence

Fibonacci (Fibonacci) sequence

  1. Find the first 40 numbers of the Fibonacci sequence. This sequence has a characteristic: the first and second numbers are 1 and 1. Starting with the third number, the number is the sum of the two preceding numbers. That is, the number sequence is 1, 1, 2, 3, 5, 8, 13....

  2. Here is an interesting classical math problem: There are a pair of rabbits, and a pair of rabbits are born every month from the third month onwards. The little rabbits will give birth to a pair of rabbits every month after the third month. Assuming that all rabbits are immortal, ask what is the total number of rabbits each month.

  3. code show as below:
    insert image description here

  4. Running result:
    .insert image description here

       .
    
  5. Program Analysis
    The program outputs a total of 40 numbers. Although the program is correct and the running result is correct, the algorithm is not the best, and each number output occupies one line, which is too large and not advisable.

Guess you like

Origin blog.csdn.net/weixin_50804299/article/details/115387504