Skip to content

Instantly share code, notes, and snippets.

@vividvilla
Last active December 11, 2015 18:19
Show Gist options
  • Save vividvilla/4641106 to your computer and use it in GitHub Desktop.
Save vividvilla/4641106 to your computer and use it in GitHub Desktop.
/* 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