java - how to get fibonacci series within range without recursion -


i trying calculate fibonacci numbers within specific range(wide range of numbers in thousands) have wrote not know to modify make within range example need fibonacci numbers between 5027 , 8386589

class fibonacci {     public static void main(string args[])     {         int n1=0,n2=1,n3,i,count=10;         system.out.print(n1+" "+n2);//printing 0 , 1          for(i=2;i<count;++i)         {           n3=n1+n2;           system.out.print(" "+n3);           n1=n2;           n2=n3;         }      } } 

 int fib(int low, int high){        // initialize first 3 fibonacci numbers        int n1 = 0, n2 = 1, n3 = 1;         // count fibonacci numbers in given range        int result = 0;         while (n1 <= high){             if (n1 >= low)                result++;             f1 = f2;             f2 = f3;             f3 = f1 + f2;         }          return result;  } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -