int fibonacci_rec(int n) { if(n < 2) { return 1; } else { return fibonacci_rec(n - 1) + fibonacci_rec(n - 2); } }
int main(){ int n; printf("Enter the value of n greater than 0 : "); scanf("%d",&n); current_timestamp(); printf("Fibonacci of n is %u\n",fibonacci_rec(n)); current_timestamp(); return 0; }
int main(int argc, char *argv[]) { assert(fibonacci(1) == 1); assert(fibonacci(2) == 1); assert(fibonacci(3) == 2); assert(fibonacci(4) == 3); assert(fibonacci(5) == 5); assert(fibonacci(6) == 8); printf("Iterative tests passed!\n"); assert(fibonacci_rec(1) == 1); assert(fibonacci_rec(2) == 1); assert(fibonacci_rec(3) == 2); assert(fibonacci_rec(4) == 3); assert(fibonacci_rec(5) == 5); assert(fibonacci_rec(6) == 8); printf("All tests passed!\n"); return EXIT_SUCCESS; }
unsigned int fibonacci_rec(int n){ if((n==1)||(n==2)) return 1; return(fibonacci_rec(n-1)+fibonacci_rec(n-2)); }
void print_fibonacci_sequence(int); void fibonacci_ggt(int); int main(int argc, char *argv[]){ // d) int n=0; if(sscanf(argv[1],"%d",&n)!=1){ //Failed to read command line arguments printf("Fehler beim lesen der Komandozeilenparameter!\n\ Bitte in folgender Form eingeben: ./fibonacci Zahl\n"); return 1; } // a) printf("Fibonacci rekursiv: %d\n",fibonacci_rec(n)); // b) printf("Fibonacci iterativ: %d\n",fibonacci_it(n)); // c) //print_fibonacci_sequence(n); // f) fibonacci_ggt(n); } // Function which calculate ggt int calc_ggt(int number1, int number2){ while (number1 != number2) { if (number1 > number2) {
int main(int argc, char *argv[]) { printf("%d", fibonacci_rec(10)); return 0; }