fibonacci/fibo.c
2022-04-29 09:45:11 +03:00

35 lines
No EOL
627 B
C

// Fibonacci number generator in ANSI C using recursion
#include <stdio.h>
#include <time.h>
#define COUNT 30
long Fibo (long x);
long Fibo (long x) {
if (x < 3)
return 1;
else
return Fibo (x-1) + Fibo (x-2);
}
int main (int argc, const char * argv[]) {
long fibo;
int i;
clock_t start, done;
start = clock();
printf("Lasketaan fibo %d \n", COUNT);
for (i = 1; i <= COUNT; i++) {
fibo = Fibo (i);
printf ("Fibo: %d - %ld\n",i, fibo);
}
done = clock();
printf("Laskenta kesti: %f sec\n",(done-start)/(double)(CLOCKS_PER_SEC));
return 0;
}