Python Program for How to Check if a Given Number is Fibonacci Number or Not

In this tutorial, we will learn how to check if the given number is a Fibonacci number or not.

Here, we have a number "n", and we have to check if it is a Fibonacci number. Starting number of Fibonacci series are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on.

Example:

We can also use the following property of the Fibonacci number for checking if the given number is a Fibonacci number or not:

  • A number is Fibonacci number only if one of (5 * R * R + 4) or ( 5 * R * R - 4) or both of them are the perfect square.

Python Program to Check if Given Number if Fibonacci or Not:

Output:

Number: 1 : Yes, the given number is a Fibonacci_Number
Number: 2 : Yes, the given number is a Fibonacci_Number
Number: 3 : Yes, the given number is a Fibonacci_Number
Number: 4 : No, the given number is not a Fibonacci_Number
Number: 5 : Yes, the given number is a Fibonacci_Number
Number: 6 : No, the given number is not a Fibonacci_Number
Number: 7 : No, the given number is not a Fibonacci_Number
Number: 8 : Yes, the given number is a Fibonacci_Number
Number: 9 : No, the given number is not a Fibonacci_Number
Number: 10 : No, the given number is not a Fibonacci_Number
Number: 11 : No, the given number is not a Fibonacci_Number
Number: 12 : No, the given number is not a Fibonacci_Number
Number: 13 : Yes, the given number is a Fibonacci_Number
Number: 14 : No, the given number is not a Fibonacci_Number
Number: 15 : No, the given number is not a Fibonacci_Number
Number: 16 : No, the given number is not a Fibonacci_Number
Number: 17 : No, the given number is not a Fibonacci_Number
Number: 18 : No, the given number is not a Fibonacci_Number
Number: 19 : No, the given number is not a Fibonacci_Number
Number: 20 : No, the given number is not a Fibonacci_Number
Number: 21 : Yes, the given number is a Fibonacci_Number

Conclusion

In this tutorial, we have discussed how a user can check if the given number is a Fibonacci number or not by using Python.






Latest Courses