未验证 提交 2882b7be 编写于 作者: F Filip Hlasek 提交者: GitHub

fix: math/fibonacci linter warnings. (#1047)

* fix: math/fibonacci linter warnings.

* updating DIRECTORY.md

* doxygen

* unit64_t instead of unsigned int
Co-authored-by: Ngithub-actions <${GITHUB_ACTOR}@users.noreply.github.com>
上级 de868c9f
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册