![]() |
VOOZH | about |
We have been given an array and our task is to check if the element of array is present in Fibonacci series or not. If yes, then print that element.
Examples:
Input : 4, 2, 8, 5, 20, 1, 40, 13, 23
Output : 2 8 5 1 13
Here, Fibonacci series will be 0, 1, 1, 2,
3, 5, 8, 13, 21, 34, 55. Numbers that are present
in array are 2, 8, 5, 1, 13
For 2 -> 5 * 2 * 2 - 4 = 16
16 is a perfect square of 4
Input : 4, 7, 6, 25
Output : No Fibonacci number in this array
A number is said to be in Fibonacci series if either (5 * n * n - 4) or (5 * n * n + 4) is a perfect square. Please refer check if a given number is Fibonacci number for details.
Implementation:
2 8 5 1 13