Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# checking wether fibanocci or not

ramjcp kris
Greenhorn
Posts: 27
can an one suggest me a program/algorithm to check wether entered number is fibanocci or not; I have written the program to generate fibanocci series ,its working fine.

Stephen Foy
Ranch Hand
Posts: 143
you could assign the fibonacci series to an array.

And then check like:

[ December 08, 2005: Message edited by: ste fing ]

Sri Ram
Ranch Hand
Posts: 118
U can use this

N is a Fibonacci number if and only if 5 N2 + 4 or 5 N2 � 4 is a square number.

write a program implementing this rule, u get the Result

georgy jacob
Ranch Hand
Posts: 53
I hope this code will be of use to you

int sum;
int i=0;
int j=1;
boolean fibo_flag = false;
do
{
sum = i+j;
i=j;
j=sum;
if(entered_num==0 || entered_num == sum)fibo_flag=true;
}
while (sum<entered_num);
if(fibo_flag) System.out.println("Numbr is fibonacci");
else System.out.println("Number is not fibonacci");