VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-the-previous-fibonacci-number/

⇱ Find the previous fibonacci number - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find the previous fibonacci number

Last Updated : 12 Jul, 2025

Given a Fibonacci number N, the task is to find the previous Fibonacci number.
Examples: 
 

Input: N = 8 
Output:
5 is the previous fibonacci number before 8.
Input: N = 5 
Output:
 


 


Approach: The ratio of two adjacent numbers in the Fibonacci series rapidly approaches ((1 + sqrt(5)) / 2). So if N is divided by ((1 + sqrt(5)) / 2) and then rounded, the resultant number will be the previous Fibonacci number. 
Below is the implementation of the above approach: 
 


Output: 
5

 

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment
Article Tags: