How to write a Fibonachi sequence in C

Updated on technology 2024-04-14
11 answers
  1. Anonymous users2024-02-07

    using system;

    using ;

    using ;

    using ;

    static void main(string args)"How many numbers are displayed");

    int sum=

    for (int i = 1; i <= sum; i++)

    public static int feibo(int n)if (n == 1 ||n == 2)

    return 1;

    elsereturn feibo(n - 1) +feibo(n - 2);

    Recursively, public static int feibo(int n).

    if (n == 1 ||n == 2)

    return 1;

    elsereturn feibo(n - 1) +feibo(n - 2);

    Find the number of numbers.

    You can have as many loops as you want.

  2. Anonymous users2024-02-06

    Fibona odd sequence, right?

    public int getfb(int num){int fb=new int[num];

    for(int ii=0;iifb[ii]=1;

    else{fb[ii]=fb[ii-1]+fb[ii-2];

    return fb;

    The parameter is the length of the series.

  3. Anonymous users2024-02-05

    #include

    void main()

    * Initialize, so that the first two elements are 1, and the other elements are 0*i=2;

    while(i<15)

    From the third element, the array element is equal to the sum of the first two elements *printf("The top 15 Fibona numbers are:");

    i=0;while(i<15)

    Output array element *}

  4. Anonymous users2024-02-04

    Method 1:

    The top 30 terms in the Fibona sequence are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040

    The sum is 2178308.

    Method 2: The general formula for the Fibona sequence is an=(p n-q n) 5, where p=(1+ 5) 2 and q=(1-5) 2.

    It is easy to use mathematical induction to prove that the first n terms of the Fibona sequence and sn=a(n+2)-1, so the first 30 terms and s30=5-1=2178308.

  5. Anonymous users2024-02-03

    Fibona's wedge sequence is written as the difference between two proportional sequences, just sum them according to the proportional sequence, and the answer is 3524577

  6. Anonymous users2024-02-02

    First of all, it is stated that the Fibonacci sequence has two forms, the difference is what the first two items start with;

    Form 1: 1 1 2 3 5 8 before n terms and s(n) f(n+2) -1

    Form 2: 1 2 3 5 8 before n term and s(n) f(n+2) -2

    The sum of the first 30 terms of Form 1: f(32) -1 = 2178309 - 1 = 2178308

    The sum of the first 30 terms of Form 2: f(32) -2 = 3524578 - 2 = 3524576

    Supplement 1: -- both for Form 2

    Main properties: -- can be used to derive the value of f(32).

    1) The first n terms of the Fibonacci sequence and s(n) = f(n+2) -1;

    2) f²(n+1) -f(n) *f(n+2) = (-1)^n;

    3) 4*f(n) 3f(n+1) 6f(n) (for n 3);

    4) f(m+n+1) = f(m+1) f(n) +f(m)f(n-1) (for m, n n+, n 1);

    5) f(2n) = f (n + 1) -f (n - 1) (for n n +, n 1).

    Supplement 2: n f(n).

  7. Anonymous users2024-02-01

    At the beginning of the 13th century, the best mathematician in Europe was Fibonacci, who wrote a book called The Book of Abacus, which was the best mathematical book in Europe at the time. There are many interesting math problems in the book, and one of them is this:

    If a pair of rabbits can give birth to a pair of rabbits per month, and each pair of rabbits can start to give birth to a pair of rabbits in the third month after its birth, assuming that a pair of newborn rabbits can be bred after a year without death?

    It's interesting to calculate the logarithm of a rabbit. For the sake of an orderly narrative, let's assume that the original pair of rabbits were born in December of the first year. Apparently, there was only one pair of rabbits in January, and by February, the pair had 1 pair of baby rabbits, for a total of 2 pairs of rabbits; In March, the pair gave birth to another pair of rabbits, for a total of 3 pairs of rabbits; By April, the rabbits born in February started to give birth to bunnies, and this month gave birth to 2 pairs of bunnies, so a total of 5 pairs of rabbits; In May, not only did the original pair of rabbits and the rabbits born in February give birth to a pair of rabbits, but the rabbits born in February also gave birth to 1 pair of rabbits, for a total of 3 pairs of rabbits, so a total of 8 pairs of rabbits .......

    If you continue to calculate in this way, you will of course get the answer to the question, but Fibonacci is not satisfied with this algorithm, he feels that this method is too cumbersome and the calculation is complicated in the end, and the slightest mistake will lead to errors. So he explored the quantitative relationship in the problem in depth, and finally found a simple way to solve the problem.

    Fibonacci puts the first few numbers in a string.

    There is an implicit rule in this string of numbers, starting with the third number, and each number that follows is the sum of the two numbers that precede it. According to this law, with some simple additions, the number of rabbits in each subsequent month can be calculated.

    In this way, it is necessary to know what the logarithm of the rabbit will be in a year, that is, what will be the 13th number of the string. From 5 8 13 , 8 13 21 , 13 21 34 , 21 34 55 , 34 55 89 , 55 89 144 , 89 144 233 , the answer to the question is 233 pairs.

    The numbers calculated according to this law constitute the famous number series in the history of mathematics. Everyone calls it the "Fibonacci sequence". This sequence has many peculiar properties, for example, from the 3rd number onwards, the ratio of each number to the number after it is very close to , which coincides with the famous "** division".

    It has also been discovered that even the laws of growth of some organisms can be described by this series of numbers under certain assumptions.

    The sequence is ......

  8. Anonymous users2024-01-31

    The general formula for the Fibona sequence is an=k1* p n + k2 * q n.

    where p and q are the two roots of x 2 = x + 1 [Note: if an = m1 * a(n-1) + m2 * a(n-2), then the two bases are x 2 = m1 * x + m2 respectively, and more terms are the same], k1 and k2 are determined by the values of a1 and a2, and the sum can be summed by the proportional sequence.

  9. Anonymous users2024-01-30

    The general formula for the Fibona sequence is an=(p n-q n) 5, where p=(1+ 5) 2 and q=(1-5) 2.

    It is easy to use mathematical induction to prove the first n terms of the Fibona sequence and sn=a(n+2)-1

    So the first 50 terms and s50 = 5-1

  10. Anonymous users2024-01-29

    1,1,2,3,5,8,13,21,34,55……

    From the third term onwards, each term is equal to the sum of the first two terms.

    It is a question put forward by the Italian mathematician Fibonaccia, assuming that a pair of newborn babies can grow into a big one month later, and then a pair of babies can be born in another month, and then a pair of rabbits are born every month, and no death occurs within a year, asking a pair of newborn rabbits, how many pairs of rabbits are bred into in a year?

  11. Anonymous users2024-01-28

    The A array is defined without allocating space to new or write a[50] directly

Related questions
11 answers2024-04-14

It's all class names, functions, and members are given to you, just do it according to which idea!

3 answers2024-04-14

Heada and headb are both singly linked lists with leading nodes. In this algorithm, we delete the common elements from the ith element in the heada linked list, and then insert the single-linked list heada before the jth element of the headb. >>>More

7 answers2024-04-14

Use cmd's timer to shut down.

private void button1_click(object sender, eventargs e) >>>More

5 answers2024-04-14

It's all as simple as that, have you ever learned C!