add FibToN
print all fibonacci till N in O(n)
This commit is contained in:
parent
8b29c6ca1d
commit
12b86774ad
21
Misc/FibToN
Normal file
21
Misc/FibToN
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user