#include <stdio.h>int fib(int n){if(n<=1) return 1;else return fib(n-1)+fib(n-2);}int main( ){int n;scanf("%d",&n);printf("%d\n" ,fib(n) );}View code
#include <stdio.h>int fib(int n){ if(n<=1) return 1; else return fib(n-1)+fib(n-2);}int main( ){ int n; while(scanf("%d",&n)) printf("%d\n" ,fib(n) );}View code
230 = (210) 3 = 109
240 = (210) 4 === 1012 250 === 1015
The 10th power of 2 is 1024
The 46 power of 2 is the 5 power of 1024 divided by the 4 power of 2 = 70368744177664.00 ======= 1013
#include <stdio.h>#define MAX 50+1int a[MAX];int fib(int n){ if (a[n]==-1) return a[n]=fib(n-1)+fib(n-2); else return a[n]; }int main( ){ int i,n; for(i=1; i<MAX; i++) a[i]=-1; a[0]=a[1]=1; scanf("%d",&n); printf("%d\n" ,fib( n ) );}View code
# Include <stdio. h>
# Define Max 50 + 1
Int A [Max];
Int fib (int n)
{If(A [n] =-1)Return A [n] = fib (n-1) + fib (n-2); // IfA [n] =-1, not counted
Else return a [n];
}
Int main ()
{
Int I, N;
For (I = 1; I <Max; I ++) A [I] =-1;// Mark, and the initial values of all elements-1
A [0] = A [1] = 1 ;//Value assignment, initialization, known condition
Scanf ("% d", & N );
Printf ("% d \ n", FIB (n ));}