recently compiled Fibonacci sequence procedures, online inadvertently found these, share with alumni ....
Fibonacci numbers in the Fibonacci sequence often appear in front of our eyes--like pine cones, the arrangement of pineapple and leaves, the number of petals of some flowers, the golden Rectangle, the Golden section, the isometric spiral, and so on, sometimes we are too keen on Fibonacci amount to divide things that were just coincidences into Fibonacci numbers. For example, the piano on the white 8, Black keys on the 5 are Fibonacci number, it should be seen as coincidence or law it. with the increase of the number of items, the former and the latter are more and more approximate to the numerical 0.6180339887 ... Starting with the second item, the square of each odd item is 1 more than the first two items, and the square of each even term is 1 less than the sum of the two items. (Note: odd and even items are the odd pairs of items , and not the number of the index column of the parity, such as the fourth 3 is odd, but it is even, the fifth item 5 is odd, it is odd, if you think the number 3 and 5 are odd items, then misunderstand the question, how can not say?
A lot of the one is where.If you see a topic like this: someone cut a 8*8 square into four pieces and spelled it into a 5*13 rectangle, so surprised to ask you: why 64=65. In fact, the use of the Fibonacci sequence of this property: 5, 8, 13 is the number of adjacent three, in fact, two block area It is 1, but there is a slender slit in the back of the picture, which is not easily noticed by the average person. C Language Program The first 40 items #include <stdio.h> int main () {long fib[41] = {0,1} with cyclic output; int i; for (i=2;i<41;i++) fib[i] = fib[i-1]+fib[i-2]; for (i=1;i<41;i++) printf ("f%d==%d\n", I,fib[i]); Getch (); return 0; (/////////////////////N. Long fib (int n) {if (n==0) return 0; if (n==1) return 1; if (n>1) return fib (n-1) +fib (n-2); int main () {int k=1; while (k!=0) {puts ("input a num n 0 for exit"); scanf ("%d", &k); printf ("%ld\n", fib (k)); } getch (); return 0; //high-precision Fibonacci sequence (3000 of the length of the 10,000th polynomial) #include <stdio.h> #include <iostream> using namespace std; int a[3001]={}; int b[3001]={}; int c[3001]={}; int n; int main () {scanf ("%d", &n); if (n<3) {printf ("%d\n", N); return 0;} c[1]=2; B[1]=1; for (int i=1;i<=n-2;i++) {for (int j=1;j<=3000;j++) {a[j]=b[j]; B[J]=C[J]; c[j]=0;} for (int j=1;j<=3000;j++) {c[j]=c[j]+a[j]+b[j]; if (c[j]>=10) {c[j]=c[j]-10; C[j+1]=1;}} int i=3000; while (c[i]==0) i--; for (i=i;i>=1;i--) printf ("%d", c[i]); printf ("\ n"); System ("pause"); return 0; }C # Language ProgramPublic class Fibonacci {//normren static void Main (string[] args) {int x = 0, y = 1; for (int j = 1; J <; J + +, y = x + y, x = y-x) console.write (y + ""); }} Java language Programs /* Fast calculates the nth Java program, calculates the 100,000th number in one second. Intel Core2 Duo CPU P8600 2.4GHz calculates the number of 100,000th Fibonacci series (milliseconds): 100000:967.8 981.1 988.8 966.3 994.4/public class F IB {//n is the number of the nth Fibonacci series public static BigInteger compute2 (int n) {if (n = = 1 | | n = = 2) {return biginteger.one; } BigInteger num1 = Biginteger.one; BigInteger num2 = Biginteger.one; BigInteger result = Biginteger.zero; for (int i = 2; i < n; i++) {result = Num1. Add (num2); num2 = NUM1; NUM1 = result; return result; } public class Fibonacci {public static void main (string[] args) {int x=1,y=1; System.out.println (x+ ""); for (int i=1;i<=20;i++) {System.out.println (y+ ""); Y=x+y;x=y-x; }}} Java language Program (high precision, about one second to calculate the No. 20000 value) import Java.util.Scanner; public class main{public static void Main (string[] args) {Scanner s=new Scanner (standard input); int N=s.nextint (); Do{cul (n); N=s.nextint (); }while (n>0)///when n<=0 terminates} private static void cul (int n){Bigintt b=new bigintt (); Bigintt a=new Bigintt (); B.formatbigint ("1"); A.formatbigint ("2"); if (n==1 | | n==2) {SYSTEM.OUT.PRINTLN (1); Return int i=3; for (; i<=n;i++) {if (i%2>0) B.add (a); else A.add (b); } Bigintt T=null; if (i%2>0) t=b; else T=a; for (int j=t.getpos (); j<100000;j++) System.out.print (T.getbase (j)); System.out.println (); class bigintt{int max=100000; Private byte[] Base=new Byte[max]; private int Pos=max; public void Formatbigint (String arr) {int l=arr.length (); if (l==0) return; int tmp=l-1; for (int i=max-1;i>=max-l;i--) {base[i]= (byte) (Arr.charat (tmp--)-' 0 '); pos--; } public void Add (Bigintt right) {int bigger=this.getpos () >right.getpos () Right.getpos (): This.getpos (); Pos=bigger; for (int i=max-1;i>=pos-2;i--) {int t=this.base[i]+right.getbase (i); if (t>=10) {this.base[i]= (byte) (T%10); THIS.BASE[I-1]+=T/10; if (I-1<pos) pos=i-1; }else{This.base[i]= (byte) t; }} public int GetPos () {return pos; public byte getbase (int index) {return base[index]; } }