Given a number of terms the task is to print Fibonacci Series using recursion.
In mathematics the Fibonacci Series is a series in which each number is the sum of the two preceding ones.
The first ten terms of Fibonacci Series are: 0 1 1 2 3 5 8 13 21 34
Java
import java.util.*;
public class FibonacciRec
{
int a=0,b=1,c=0;
public void genFibo(int n)
{
if(n==0)
{
return;
}
else
{
System.out.println(a);
c=a+b;
a=b;
b=c;
genFibo(n-1);
}
}
public static void main(String args[])
{
int n=0;
Scanner sc=new Scanner(System.in);
FibonacciRec ob=new FibonacciRec();
System.out.print("Enter the limit: ");
n=sc.nextInt();
ob.genFibo(n);
}
}Java