int main(int argc, char **argv) { time_t start_tm, finish_tm; time(&start_tm); int number=0; int result=0; scanf("%d",&number); result = fibN(number); printf("The fibonacci sequence at %d is: %d\n", number, result); time(&finish_tm); double elapsed_tm=difftime(finish_tm,start_tm); printf("Recursive for %10.10f seconds.\n", elapsed_tm); }
//1 1 2 3 5 8 13 21 34 55 .. //1 2 3 4 5 6 7 8 9 10 .. unsigned fibN(unsigned n){ if (n <= 2){ return 1; } return fibN(n - 1) + fibN(n - 2); }
int main() { std::cout << fibN(6); return 0; }
fibN(int x){ if(x<=0)return 0; if(x==1)return 1; return fibN(x-1)+fibN(x-2); }
/* Signature of the JNI method as generated in header file */ JNIEXPORT jlong JNICALL Java_com_liuapps_fibonacci_FibLib_fibN (JNIEnv *env, jclass obj, jlong n) { return fibN(n); }
long fibN(long n) { if(n<=0) return 0; if(n==1) return 1; return fibN(n-1) + fibN(n-2); }