fibonacci/fibo.c

34 lines
618 B
C
Raw Normal View History

2022-04-29 08:45:42 +03:00
// Fibonacci number generator in ANSI C using recursion
#include <stdio.h>
#include <time.h>
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);
}