mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-04 19:20:17 +08:00
fibonacci documentation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user