Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

nth fibonacci number

// Find N-th fibonacci number using recursion

#include <bits/stdc++.h>
using namespace std;

int fibo(int n)
{
    if (n == 1)
        return 1;
    if (n == 2)
        return 1;
    return fibo(n - 1) + fibo(n - 2);
}

int main()
{
    int n, T;
    cin >> T;
    while (T--)
    {
        cin >> n;
        cout << fibo(n) << endl;
    }

    return 0;
}
 
PREVIOUS NEXT
Tagged: #nth #fibonacci #number
ADD COMMENT
Topic
Name
8+4 =