import java.util.*; public class FibRecursion { int fibSeries(int n){ if(n<=1) { return n; } return fibSeries(n-1)+fibSeries(n-2); } public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("\n Enter Limit..."); int N = scan.nextInt(); FibRecursion f = new FibRecursion(); f.fibSeries(N); for(int i=0; i<N; i++) { System.out.print(" " + f.fibSeries(i)); } } } Output: Enter Limit... 10 0 1 1 2 3 5 8 13 21 34
Basic Java programs. All programs done in very simple ways. It helps beginners to grow their programming skills and build a programming logic.
Monday, 7 December 2020
Fibonacci Series using Recursion
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
If you have any doubts, please let me know