We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Recursion: Fibonacci Numbers
- Discussions
Recursion: Fibonacci Numbers
Recursion: Fibonacci Numbers
Sort by
recency
|
302 Discussions
|
Please Login in order to post a comment
include
using namespace std;
int fibonacci(int n) {
if (n==0||n==1) return n; else return fibonacci(n-1)+fibonacci(n-2); }
int main() { int n; cin >> n; cout << fibonacci(n); return 0; }
RUST:
def fibonacci(n): a, b = 1, 1 for _ in range(n - 1): a, b = b, a + b return a
It's weird to me that the Fibonacci sequence is academically used as the "hello world" of recursion because I mean: