C_Algorithms 2.0.0
Documentation
Loading...
Searching...
No Matches
dynamicFib.c
Go to the documentation of this file.
1#include <stdio.h>
2
3#include "dynamicFib.h"
4
12long DynFib(int n)
13{
14 if (n <= 2)
15 return 1;
16 long array[n - 1];
17 array[0] = 1; // Basevalue for fibonacci 1 = 1
18 array[1] = 1; // Basevalue for fibonacci 2 = 1
19
20 // Safe value from the n th fibonacci number in array[n - 1]
21 for (long i = 2; i < n; i++)
22 array[i] = array[i - 1] + array[i - 2];
23 return array[n - 1]; // Return the value
24}
25
31void DynamicFib(int number)
32{
33 printf("%ld\n", DynFib(number));
34}
long DynFib(int n)
DynFib is a function that is calculating the fibonacci number dynamic. It's a lot faster as the recur...
Definition dynamicFib.c:12
void DynamicFib(int number)
Prints the return value of the called function RecFib.
Definition dynamicFib.c:31