diff --git a/fibo.c b/fibo.c new file mode 100644 index 0000000..933b472 --- /dev/null +++ b/fibo.c @@ -0,0 +1,34 @@ +// Fibonacci number generator in ANSI C using recursion +#include +#include + +long Fibo (long x); + +int main (int argc, const char * argv[]) { + + long fibo; + int i, count; + clock_t start, done; + + count = 40; + start = clock(); + + printf("Lasketaan fibo %d \n", count); + + for (i = 1; i <= count; i++) { + fibo = Fibo (i); + printf ("%d - %ld\n",i, fibo); + } + + done = clock(); + printf("aika: %f s\n",(done-start)/(double)(CLOCKS_PER_SEC)); + + return 0; +} + +long Fibo (long x) { + if (x < 3) + return 1; + else + return Fibo (x-1) + Fibo (x-2); +} \ No newline at end of file