Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fibonacci stairs
//Title of this code #include <iostream> using namespace std; int stairs(int n) { if (n < 1) return 0; if (n == 1 || n == 2) return 1; int i = 2; int a = 1, b = 1, c = 1; while (i < n) { ++i; c = a + b; a = b; b = c; } return c; } long long fib(int n) { if (n < 1) return 0; if (n == 1) return 1; if (n == 2) return 1; long long a = 1, b = 1, c; int i = 2; do { c = a + b; a = b + c; b = c + a; i += 3; } while (i < n); if (i == n) return b; if (i - 1 == n) return a; return c; } int main() { for (int i = -4; i < 20; ++i) cout << stairs(i) << " "; cout << endl; for (int i = -4; i < 20; ++i) cout << fib(i) << " "; }
run
|
edit
|
history
|
help
0
For NULL-embedded strings, CStringT::Find() produces what you may not expect
#8
PRIx64 on MSVC
multiplie linked list numbers
default
Overload
It complies!
masodijegy.cpp
Wide string conversion with multibyte chars and locale
32