#include <stdio.h> #include <stdlib.h> unsigned long fibonacciRec(int n) { if(n < 2) return 1UL; return fibonacciRec(n-1) + fibonacciRec(n-2); } unsigned long fibonacci(int n) { int i; unsigned long fn1, fn2, fn; fn = fn1 = fn2 = 1UL; for(i = 2; i <= n; i++) { fn = fn1 + fn2; fn2 = fn1; fn1 = fn; } return fn; } int main(int argc, char *argv[]) { int i; printf("Fibonacci recursiva:\n"); for(i = 0; i < 30; i++) printf("F(%d)=%10lu\n", i, fibonacciRec(i)); getchar(); printf("Fibonacci iterativa:\n"); for(i = 0; i < 30; i++) printf("F(%d)=%10lu\n", i, fibonacci(i)); return EXIT_SUCCESS; }