First commit
This commit is contained in:
parent
7a65e4365d
commit
4fac86fe54
1 changed files with 34 additions and 0 deletions
34
fibo.c
Normal file
34
fibo.c
Normal 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);
|
||||||
|
}
|
Loading…
Reference in a new issue