From 12b86774ad06857051e687fe85521de1fd29c70f Mon Sep 17 00:00:00 2001 From: Deepak Date: Mon, 2 Oct 2017 12:53:43 +0530 Subject: [PATCH] add FibToN print all fibonacci till N in O(n) --- Misc/FibToN | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Misc/FibToN diff --git a/Misc/FibToN b/Misc/FibToN new file mode 100644 index 00000000..4d002b8f --- /dev/null +++ b/Misc/FibToN @@ -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; + } + } + +}