Skip to content

Commit 12b8677

Browse files
authored
add FibToN
print all fibonacci till N in O(n)
1 parent 8b29c6c commit 12b8677

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Misc/FibToN

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.Scanner;
2+
3+
public class FibToN {
4+
5+
public static void main(String[] args) {
6+
Scanner scn = new Scanner(System.in);
7+
8+
int n = scn.nextInt();
9+
10+
int fn = 0, sn = 1;
11+
12+
while(fn <= n){
13+
System.out.println(fn);
14+
15+
int next = fn + sn;
16+
fn = sn;
17+
sn = next;
18+
}
19+
}
20+
21+
}

0 commit comments

Comments
 (0)