mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fibonacci documentation
This commit is contained in:
parent
c27fa436b8
commit
6dfdfa6662
@ -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);
|
||||
|
@ -1,11 +1,14 @@
|
||||
/**
|
||||
* Computes N^th Fibonacci number given as
|
||||
* @file
|
||||
* @brief Computes N^th Fibonacci number given as
|
||||
* input argument. Uses custom build arbitrary integers library
|
||||
* to perform additions and other operations.
|
||||
*
|
||||
* Took 0.608246 seconds to compute 50,000^th Fibonacci
|
||||
* number that contains 10450 digits!
|
||||
**/
|
||||
*
|
||||
* @see fibonacci.cpp
|
||||
*/
|
||||
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
@ -13,6 +16,10 @@
|
||||
|
||||
#include "./large_number.h"
|
||||
|
||||
/** Compute fibonacci numbers using the relation
|
||||
* \f[f(n)=f(n-1)+f(n-2)\f]
|
||||
* and returns the result as a large_number type.
|
||||
*/
|
||||
large_number fib(uint64_t n) {
|
||||
large_number f0(1);
|
||||
large_number f1(1);
|
||||
|
Loading…
Reference in New Issue
Block a user