First commit

This commit is contained in:
Nyymix 2022-04-29 08:45:42 +03:00
parent 7a65e4365d
commit 4fac86fe54

34
fibo.c Normal file
View file

@ -0,0 +1,34 @@
// 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);
}