Last active
December 11, 2015 18:19
-
-
Save vividvilla/4641106 to your computer and use it in GitHub Desktop.
Fibonacci Series in Java using Recursive function - http://vivek.techiestuffs.com/2012/fibonacci-series-in-java-using-recursive-function/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Java Program to print first N terms of Fibonacci series using Recursive function (without taking input from user) | |
* Code by Vivek R (vividvilla) - Contact me at - http://vivek.techiestuffs.com | |
*/ | |
public class FibonacciRecursive | |
{ | |
public static void main(String[] args) | |
{ | |
int n=10,i,j=0; | |
System.out.println("Printing first "+n+" numbers in Fibonacci Series \n"); | |
for(i=1;i<=n;i++) | |
{ | |
System.out.print(fib(j)+"\t"); | |
j++; | |
} | |
} | |
public static int fib(int n) | |
{ | |
if ( n == 0 ) | |
return 0; | |
else | |
if ( n == 1 ) return 1; | |
else | |
return ( fib(n-1) + fib(n-2) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment