add FibToN

print all fibonacci till N in O(n)
This commit is contained in:
Deepak 2017-10-02 12:53:43 +05:30 committed by GitHub
parent 8b29c6ca1d
commit 12b86774ad

21
Misc/FibToN Normal file
View File

@ -0,0 +1,21 @@
import java.util.Scanner;
public class FibToN {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int fn = 0, sn = 1;
while(fn <= n){
System.out.println(fn);
int next = fn + sn;
fn = sn;
sn = next;
}
}
}