how to print if a given no. is a fabonnici series or not
Problem solving
yes, how to do it ???
@sujeetmandloi23 hey nitin see this
Finding if a number is Fibonacci number or not:
One way to check if a number is Fibonacci is to keep finding Fibonacci numbers till we get a number greater than or equal to. For example, to check if a number ‘n’ is Fibonacci or not:
int checkfibonacci(int n)
{
int a = 0;
int b = 1;
if (n==a || n==b) return true;
int c = a+b;
while(c<n)
{
if(c == n) return true;
a = b;
b = c;
c = a + b;
}
return false;
}
Another method (Quick one) to check if a number if Fibonacci number or not, is as below:
N is a Fibonacci number if and only if ( 5N2 + 4 ) or ( 5N2 – 4 ) is a perfect square!
For Example:
3 is a Fibonacci number since (533 + 4) is 49 which is 77
5 is a Fibonacci number since (555 – 4) is 121 which is 1111
4 is not a Fibonacci number since neither (544 + 4) = 84 nor (544 – 4) = 76 are perfect squares.
where to take input (n)
and give o/p