2017-10-02 15:23:43 +08:00
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
public class FibToN {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2017-10-03 15:55:06 +08:00
|
|
|
//take input
|
2017-10-02 15:23:43 +08:00
|
|
|
Scanner scn = new Scanner(System.in);
|
2017-10-03 15:55:06 +08:00
|
|
|
int N = scn.nextInt();
|
|
|
|
// print fibonacci sequence less than N
|
|
|
|
int first = 0, second = 1;
|
|
|
|
//first fibo and second fibonacci are 0 and 1 respectively
|
2017-10-02 15:23:43 +08:00
|
|
|
|
2017-10-03 15:55:06 +08:00
|
|
|
while(first <= N){
|
|
|
|
//print first fibo 0 then add second fibo into it while updating second as well
|
|
|
|
|
|
|
|
System.out.println(first);
|
2017-10-02 15:23:43 +08:00
|
|
|
|
2017-10-03 15:55:06 +08:00
|
|
|
int next = first+ second;
|
|
|
|
first = second;
|
|
|
|
second = next;
|
2017-10-02 15:23:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|