[c]代码库
#include <stdio.h>
#define TARGET 40
int getjc(int i) {
if (i==1) return 1;
else return i*getjc(i-1);
}
int fib_1(int a) {
int x,y=1,s=1;
if (a==0) return 0;
for (;a>2;a--) {
x=y;
y=s;
s=x+y;
}
return s;
}
int fib_2(int a) {
if (a==1) return 1;
if (a==0) return 0;
return fib_2(a-1)+fib_2(a-2);
}
int addorder(int n,int x,int y) {
if (n==0) return x;
if (n==1) return y;
else return addorder(--n,y,x+y);
}
int fib_3(int a) {
if (a<2) return a;
return addorder(a,0,1);
}
int main() {
printf("%d\n",fib_1(TARGET));
printf("%d\n",fib_2(TARGET));
printf("%d\n",fib_3(TARGET));
return 0;
}