Program to Check Whether a Number is Fibonacci Number/Series or Not!

FibonacciNo.java

class FibonacciNo
 {
     public static void main(String args[])
 {
     int n=15;   //size of upper limit
  int a=0;   
  int b=1;  
   int c=a+b;  
   while(c<=n)  
   {      
   System.out.print(""+c);   
      c=a+b;      
   a=b;    
     b=c;    
 }   
 }
 }

/*OUTPUT
1 1 2 3 5 8 13
*/
0Shares

Leave a Reply