top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find-out if given number is Fibannaci number?

+3 votes
767 views
How to find-out if given number is Fibannaci number?
posted Nov 28, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
 
Best answer

Check the following program based on property n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both is a perfect square

bool isPerfectSquare(int x)
{
    int s = sqrt(x);
    return (s*s == x);
}

bool isFibonacci(int n)
{
        return isPerfectSquare(5*n*n + 4) ||
           isPerfectSquare(5*n*n - 4);
}
answer Nov 28, 2013 by Jai Prakash
+1 vote

A simple way is to generate Fibonacci numbers until the generated number is greater than or equal to ‘n’.

However a other property of this number can be used is "A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square (Source: Wiki)."

answer Nov 28, 2013 by Salil Agrawal
Similar Questions
+5 votes

Help me to write a C program which can generate list of numbers which are palindrome in decimal and octal notion. You can take some max as a limit find out all numbers which satisfy the given property between 1 to n.

+3 votes

Say the given string is ABC

Output should be ABC ACB BAC BCA CBA CAB

+8 votes

Convert the given string into palindrome with minimum number of appends(at end of the given string). O(n) algorithm will be appreciated ??

Input :=> Malayal
Output :=> Malayalam

...