Fibonacci number generator in ANSI C, Python and Java using recursion
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
627 B

// 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;
}