import java.io.Console;
import static java.lang.System.out;
class Fibonacci
{
static public void main(String args[])
{
Console c=System.console();
int n=Integer.parseInt(c.readLine("Enter a Number : "));
int a=0,b=1,fab=0;
while(fab<n)
{
fab=a+b;
b=a;
a=fab;
out.print(fab+" ");
}
out.println();
if(fab==n)
out.println(n+" belongs to fibonacci no");
else
out.println(n+" does not belong to fibonacci no");
}
}
0 Comment to "Write a java program to take a number and check whether it belongs to the Fibonacci Series or not. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ..."
Post a Comment