Nth Fibonacci Number

Posted: 19 Apr, 2017
Difficulty: Easy


Try Problem

Nth term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula -

    F(n) = F(n-1) + F(n-2), 
    Where, F(1) = F(2) = 1

Provided N you have to find out the Nth Fibonacci Number.

Input Format :
The first line of each test case contains a real number ‘N’.
Output Format :
For each test case, return its equivalent Fibonacci number.
1 <= N <= 10000     
Where ‘N’ represents the number for which we have to find its equivalent Fibonacci number.

Time Limit: 1 second
Approach 1
  • In this approach, we use recursion and uses a basic condition that :
    • If ‘N’ is smaller than ‘1’(N<=1) we return ‘N’
    • Else we call the function again as ninjaJasoos(N-1) + ninjaJasoos(N-2).
  • In this way, we reached our answer.
Try Problem