# Algorithms_in_C++: math/fibonacci.cpp File Reference

fibonacci.cpp File Reference

Generate fibonacci sequence. More...

`#include <cassert>`
`#include <iostream>`
Include dependency graph for fibonacci.cpp:

## Functions

int | fibonacci (unsigned int n)
int | main ()
| Main function.

## Detailed Description

Generate fibonacci sequence.

Calculate the the value on Fibonacci's sequence given an integer as input.

\[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\]

See also
  fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp

## Function Documentation

## fibonacci()

int fibonacci | ( | unsigned int | n | ) |

Recursively compute sequences

{
/* If the input is 0 or 1 just return the same
This will set the first 2 values of the sequence */
if (n <= 1)
return n;
/* Add the last 2 values of the sequence to get next */
return fibonacci(n - 1) + fibonacci(n - 2);
}
fibonacci
int fibonacci(unsigned int n)
Definition: fibonacci.cpp:17