Pages

Friday, May 23, 2025

Nth Fibonacci (Code) Using Recursion in C++

 #include <iostream>

using namespace std;

int fibonacci(int n) {
    if(n == 0 || n == 1) {
        return n; // 0, 1
    }

    return fibonacci(n-1)+fibonacci(n-2);
}

int main() {
    cout << fibonacci(3) << endl;

    return 0;
}


OUTPUT:
2

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...