Loading...
Searching...
No Matches
fibonacci.cpp File Reference
n-th Fibonacci number. More...
#include <cstdint>
#include <cassert>
#include <iostream>
Include dependency graph for fibonacci.cpp:
Go to the source code of this file.
Namespaces namespace math for assertn-th Fibonacci number.
Naive recursive implementation to calculate the n-th Fibonacci number.
\[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\]
Definition in file fibonacci.cpp.
Function Documentation ◆ fibonacci() uint64_t math::fibonacci::fibonacci ( uint64_t n )Function to compute the n-th Fibonacci number.
Definition at line 32 of file fibonacci.cpp.
32 {
33 // If the input is 0 or 1 just return the same (Base Case)
34 // This will set the first 2 values of the sequence
35 if (n <= 1) {
36 return n;
37 }
38
39 // Add the preceding 2 values of the sequence to get next
41}
Functions for Fibonacci sequence.
◆ main()Main function.
Definition at line 64 of file fibonacci.cpp.
64 {
65 test();
// run self-test implementations66 return 0;
67}
static void test()
Self-test implementation.
◆ test()Self-test implementation.
Definition at line 49 of file fibonacci.cpp.
49 {
57 std::cout << "All tests have passed successfully!\n";
58}
uint64_t fibonacci(uint64_t n)
Function to compute the n-th Fibonacci number.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4