fibonacci documentation

This commit is contained in:
Krishna Vedala
2020-05-27 17:58:17 -04:00
parent c27fa436b8
commit 6dfdfa6662
2 changed files with 13 additions and 3 deletions

View File

@@ -5,6 +5,8 @@
* Calculate the the value on Fibonacci's sequence given an
* integer as input.
* \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f]
*
* @see fibonacci_large.cpp
*/
#include <cassert>
#include <iostream>
@@ -15,7 +17,8 @@
int fibonacci(unsigned int n) {
/* 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;
if (n <= 1)
return n;
/* Add the last 2 values of the sequence to get next */
return fibonacci(n - 1) + fibonacci(n - 2);