mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix: math/fibonacci linter warnings. (#1047)
* fix: math/fibonacci linter warnings. * updating DIRECTORY.md * doxygen * unit64_t instead of unsigned int Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
de868c9faa
commit
2882b7bec2
@ -13,12 +13,15 @@
|
||||
|
||||
/**
|
||||
* Recursively compute sequences
|
||||
* @param n input
|
||||
* @returns n-th element of the Fbinacci's sequence
|
||||
*/
|
||||
unsigned int fibonacci(unsigned int n) {
|
||||
uint64_t fibonacci(uint64_t 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)
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Add the last 2 values of the sequence to get next */
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
@ -30,27 +33,27 @@ unsigned int fibonacci(unsigned int n) {
|
||||
* @returns `void`
|
||||
*/
|
||||
static void test() {
|
||||
unsigned int test_case_1 = fibonacci(0);
|
||||
uint64_t test_case_1 = fibonacci(0);
|
||||
assert(test_case_1 == 0);
|
||||
std::cout << "Passed Test 1!" << std::endl;
|
||||
|
||||
unsigned int test_case_2 = fibonacci(1);
|
||||
uint64_t test_case_2 = fibonacci(1);
|
||||
assert(test_case_2 == 1);
|
||||
std::cout << "Passed Test 2!" << std::endl;
|
||||
|
||||
unsigned int test_case_3 = fibonacci(2);
|
||||
uint64_t test_case_3 = fibonacci(2);
|
||||
assert(test_case_3 == 1);
|
||||
std::cout << "Passed Test 3!" << std::endl;
|
||||
|
||||
unsigned int test_case_4 = fibonacci(3);
|
||||
uint64_t test_case_4 = fibonacci(3);
|
||||
assert(test_case_4 == 2);
|
||||
std::cout << "Passed Test 4!" << std::endl;
|
||||
|
||||
unsigned int test_case_5 = fibonacci(4);
|
||||
uint64_t test_case_5 = fibonacci(4);
|
||||
assert(test_case_5 == 3);
|
||||
std::cout << "Passed Test 5!" << std::endl;
|
||||
|
||||
unsigned int test_case_6 = fibonacci(15);
|
||||
uint64_t test_case_6 = fibonacci(15);
|
||||
assert(test_case_6 == 610);
|
||||
std::cout << "Passed Test 6!" << std::endl << std::endl;
|
||||
}
|
||||
@ -58,7 +61,7 @@ static void test() {
|
||||
/// Main function
|
||||
int main() {
|
||||
test();
|
||||
int n;
|
||||
int n = 0;
|
||||
std::cin >> n;
|
||||
assert(n >= 0);
|
||||
std::cout << "F(" << n << ")= " << fibonacci(n) << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user