int Fibonacci(int num) { if ((num == 0) || (num == 1)) { return num; } return Fibonacci(num-1) + Fibonacci(num-2); }
int FibonacciR::Fibonacci(const int &n){ if(n==0) return 0; else if(n==1) return 1; return Fibonacci(n-1) + Fibonacci(n-2); }
int Fibonacci(int n) { if(n==0 || n==1) return 1; else return Fibonacci(n-1) + Fibonacci(n-2); }
void Fibonacci(__int64 n, BIGNUM &rez) { BIGNUM f1, f2; if (n < HASH) memcpy(rez, Table[n], sizeof(Table[n])); else { memset(rez, 0, sizeof(rez)); if (n & 1) // f[2n-1] = f^2[n] + f^2[n-1] { Fibonacci((n + 1) / 2, f1); Fibonacci(n / 2, f2); BigMul(rez, f1, f1); memset(f1, 0, sizeof(f1)); BigMul(f1, f2, f2); BigAdd(rez, f1); } else // f[2n] = f[n]*(f[n-1] + f[n+1]) { Fibonacci(n / 2 - 1, f1); Fibonacci(n / 2 + 1, f2); BigAdd(rez, f1); BigAdd(rez, f2); Fibonacci(n / 2, f1); BigMul(rez, rez, f1); } } }
void FibonacciNR::PrintFibonacci() { int result = Fibonacci(n_); for (int i = 0; i < 1000000; i++) { Fibonacci(n_); } std::cout << n_ << "th nonrecursive fibonacci Number: " << result << std::endl; }
/* * ===================================================================================== * * Filename: code8.cpp * Description: 递归 * Created: 2015年05月08日 20时14分59秒 * Author: hudmok (HangDian), [email protected] * * ===================================================================================== */ unsigned int Fibonacci(unsigned int n) { if(n<2) return n; else return Fibonacci(n-1)+Fibonacci(N-2); }
long long Fibonacci(int n) { if(n<=1) return n; if(Data[n] != 0) return Data[n]; Data[n] = Fibonacci(n-1)+Fibonacci(n-2); return Data[n]; }
int Fibonacci(int n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); }
int Fibonacci(int i) { if (i == 0) return 0; else if (i == 1) return 1; else return ( Fibonacci(i - 1) + Fibonacci(i - 2)); }
/** * Fibonacci Number */ int Fibonacci( int const& F ) { // Handle Exit Conditions if( F < 2 ){ return F; } // Otherwise return Fibonacci( F-1 ) + Fibonacci( F-2 ); }
int Fibonacci(int n) { int x, y; if (n < 2) return n; else { x = Fibonacci(n - 1); y = Fibonacci(n - 2); return (x + y); } }
// not mine: static uint FibCheck(uint n) { if (n <= 0) { return 0; } else if (n <= 2) { return n; } else { return Fibonacci(n - 1) + Fibonacci(n - 2); } }
//µÝ¹é°æ±¾ long long Fibonacci(unsigned int n) { if(n<=0) return 0; if(n==1) return 1; return Fibonacci(n-1) + Fibonacci(n-2); }
// 1 1 2 3 5 8 13 21 34... int Fibonacci(int n) { if (n == 1) return 1; else if (n == 2) return 1; int ret = Fibonacci(n - 1) + Fibonacci(n - 2); return ret; }
long long Fibonacci(long long n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); }
int Fibonacci(int n) { switch(n) { case 0: return 0; case 1: return 1; default: return ( Fibonacci(n-1) + Fibonacci(n-2) ); } }
// compiler clang++ -g -std=c++11 int main() { int fib1[] = { Fibonacci(12), Fibonacci(10) }; int fib2[] = { FibonacciTemplate<12>::value, FibonacciTemplate<10>::value }; }
int Fibonacci(int a) { if (a == 0) { //第零項為一 return 1; } else if (a == 1 || a == 2) { //第一、二項為二 return 2; } else { return 2 * Fibonacci(a - 1) + Fibonacci(a - 2) - Fibonacci(a - 3); //第三項 = 2 * 第二項 + 第一項 - 第零項 } }
int Fibonacci(int number) { if ( number == 0 ) return 0; else if ( number == 1 ) return 1; else return ( Fibonacci(number-1) + Fibonacci(number-2) ); }
int Fibonacci(int x){ if(x==1){ return 1; } else if(x==2){ return 1; } else{ return Fibonacci(x-1)+Fibonacci(x-2); } }
/* Número máximo de valores */ void printFibonacci(int max_index, int atual) { if (atual <= max_index) { if (atual == max_index) printf("%d.\n", Fibonacci(atual)); else printf("%d, ", Fibonacci(atual)); printFibonacci(max_index, atual + 1); } }
int FibonacciTask(int n) { int x, y; if (n < 2) return n; else { #pragma omp task shared(x) x = Fibonacci(n - 1); #pragma omp task shared(y) y = Fibonacci(n - 2); #pragma omp taskwait return (x + y); } }
// 求斐波拉契数列 int Fibonacci(int n) { int a, b; if (n == 0 || n == 1) return n; a = Fibonacci(n - 1); b = Fibonacci(n - 2); //assert(a + b > 0); return (a + b); }
unsigned int Fibonacci(unsigned int fib_value) { // If greater than 0 // unsigned int temp = 1; if(fib_value == 0) {return 0;} if(fib_value == 1) {return 1;} // temp +=1; return Fibonacci(fib_value - 1) + Fibonacci(fib_value - 2); // Else, return 0; // Call Fibonacci() }
int Fibonacci(int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } return Fibonacci(n - 1) + Fibonacci(n -2); }
void test500FibSub499Fib() { std::chrono::time_point<std::chrono::system_clock> start, end; std::chrono::duration<double> elapsed_time; BigInt fib500 = Fibonacci(500); BigInt fib499 = Fibonacci(499); start = std::chrono::system_clock::now(); BigInt subFibs = fib500 - fib499; end = std::chrono::system_clock::now(); elapsed_time = end - start; #ifdef _PRINT_VALS std::cout<< "500FibSub499Fib took: " << elapsed_time.count() << " computing " << subFibs << std::endl; #endif BigInt actual = Fibonacci(498); std::cout << "Fib(500) - Fib(499) Correct? " << (subFibs == actual) << std::endl; }
int main(int argc, char* argv[]) { /* Functional Test */ std::cout << Fibonacci(5) << std::endl; /* Boundary Test */ std::cout << Fibonacci(0) << std::endl; std::cout << Fibonacci(1) << std::endl; std::cout << Fibonacci(2) << std::endl; /* Performance Test */ std::cout << Fibonacci(100) << std::endl; /* Particular Test */ }
int Fibonacci(int n) { if ( n == 0 ) { return 0; } else if ( n == 1 ) { return 1; } else { return ( Fibonacci(n-1) + Fibonacci(n-2) ); } }
int main(int argc, const char * argv[]) { pid_t pid; pid=fork(); if (pid==0) { int fib =Fibonacci(1); exit(fib); } else if (pid>0){ int stato; waitpid(pid,&stato,0); if (WIFEXITED(stato)>0 && WIFEXITED(stato)<=50) { pid=fork(); if (pid ==0){ execlp("ls", "ls","-al","a.out",NULL); exit(0); } waitpid(pid, NULL,0); printf("Fine\n"); } else{ printf("Frateeeee\n"); exit(0); } } return 0; }
int main() { unsigned int n; while(scanf("%d",&n) != EOF) printf("%lld\n",Fibonacci(n)); return 0; }