mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
formatting source-code for c7ff9d66f1
This commit is contained in:
parent
c7ff9d66f1
commit
4c6b3b86c1
@ -19,7 +19,7 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
/**
|
||||
* maximum number that can be computed - The result after 93 cannot be stored
|
||||
* in a `uint64_t` data type.
|
||||
*/
|
||||
@ -28,16 +28,19 @@
|
||||
|
||||
/** Algorithm */
|
||||
uint64_t fib(uint64_t n) {
|
||||
static uint64_t f1 = 1, f2 = 1; // using static keyword will retain the values of f1 and f2 for the next function call.
|
||||
|
||||
static uint64_t f1 = 1,
|
||||
f2 = 1; // using static keyword will retain the values of
|
||||
// f1 and f2 for the next function call.
|
||||
|
||||
if (n <= 2)
|
||||
return f2;
|
||||
if (n >= 93) {
|
||||
std::cerr << "Cannot compute for n>93 due to limit of 64-bit integers\n";
|
||||
std::cerr
|
||||
<< "Cannot compute for n>93 due to limit of 64-bit integers\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t temp = f2; // we do not need temp to be static
|
||||
uint64_t temp = f2; // we do not need temp to be static
|
||||
f2 += f1;
|
||||
f1 = temp;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user