Fibonacci series:
It is also called the golden split series, which refers to a series of 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,144 ,...
In mathematics, the Fibonacci series are defined as follows by recursive Methods: F0 = 0, F1 = 1, Fn = F (n-1) + F (n-2) (n> = 2, n, N *),
That is, this series starts from the second item, and each item is equal to the sum of the first two items.
Note: 0 is 0th items, not 1st items.
Use recursion to obtain the Fibonacci sequence and list all items:
# Include
Int fun (int n) // n indicates the number of items. Note: 0 is 0th items, not 1st items. {If (n <= 1) return n; else return fun (n-1) + fun (n-2);} int main () {int n; printf ("Enter the number of items to output (Natural Number) Fibonacci sequence:"); scanf ("% d", & n); // int * a = (int *) malloc (n + 1) * sizeof (int); // if you need to store, use dynamic memory to allocate n + 1 space for int I storage; for (I = 0; I <n + 1; I ++) // output all items {printf ("% d,", fun (I); if (I! = 0 & I % 5 = 0) // wrap each of the five items (the first line contains one more than 0th items) printf ("\ n ");} printf ("item % d is: % d \ n", n, fun (n); // return 0 ;}
For example, 30th items (0-30 items are printed by the way)