mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
document fibonacci program
This commit is contained in:
parent
e31ee6e833
commit
49fe1b11ef
@ -1,12 +1,17 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Generate fibonacci sequence
|
||||
*
|
||||
* 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]
|
||||
*/
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
/* Calculate the the value on Fibonacci's sequence given an
|
||||
integer as input
|
||||
Fibonacci = 0, 1, 1, 2, 3, 5,
|
||||
8, 13, 21, 34, 55,
|
||||
89, 144, ... */
|
||||
|
||||
/**
|
||||
* Recursively compute sequences
|
||||
*/
|
||||
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 */
|
||||
@ -16,6 +21,7 @@ int fibonacci(unsigned int n) {
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
/// Main function
|
||||
int main() {
|
||||
int n;
|
||||
std::cin >> n;
|
||||
|
Loading…
Reference in New Issue
Block a user