Fibonacci numbers are numbers such that each number is the result of adding two preceding numbers. A sequence of such numbers is called as fibonacci numbers.
Fibonacci sequence start with 1, 1 as the first 2 terms.
Fibonacci sequence is 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , ....
If we want to check if a number is a fibonacci number or not we only need to check if
5*number*number - 4 or 5*number*number + 4 is a perfect square or not.
To see the derivation of the above formula click here.
C++ Program
Sample input and output to check the program
You might also be interested in
Finding Factorial of a number
Finding the next smallest Palindrome
Implement Binary Search Tree
Implement Linked List
Implement Doubly Linked List
Comments
Post a Comment