C_Algorithms 2.0.0
Documentation
Loading...
Searching...
No Matches
Functions
dynamicFib.c File Reference
#include <stdio.h>
#include "dynamicFib.h"
Include dependency graph for dynamicFib.c:

Go to the source code of this file.

Functions

long DynFib (int n)
 DynFib is a function that is calculating the fibonacci number dynamic. It's a lot faster as the recursive Version especally with bigger numbers.
 
void DynamicFib (int number)
 Prints the return value of the called function RecFib.
 

Function Documentation

◆ DynamicFib()

void DynamicFib ( int number)

Prints the return value of the called function RecFib.

Parameters
number

Definition at line 31 of file dynamicFib.c.

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

References DynFib().

Referenced by FunctionCall().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DynFib()

long DynFib ( int n)

DynFib is a function that is calculating the fibonacci number dynamic. It's a lot faster as the recursive Version especally with bigger numbers.

Parameters
ninput as an int
Returns
long Returns the nth fibonacci number

Definition at line 12 of file dynamicFib.c.

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}

Referenced by DynamicFib().

Here is the caller graph for this function: