From 4fac86fe54748ba49e2a9dea2e918ccfbf5d5703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9DNyymix=E2=80=9D?= Date: Fri, 29 Apr 2022 08:45:42 +0300 Subject: [PATCH] First commit --- fibo.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 fibo.c diff --git a/fibo.c b/fibo.c new file mode 100644 index 0000000..933b472 --- /dev/null +++ b/fibo.c @@ -0,0 +1,34 @@ +// Fibonacci number generator in ANSI C using recursion +#include +#include + +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); +} \ No newline at end of file