Q.12 Print Fibonacci Series using Recursion.import java.util.Scanner;
public class fiborec
{
static int fibo(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
else
return (fibo(n-1)+fibo(n-2));
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter n value");
int n=sc.nextInt();
for(int c=0;c<=n;c++){
System.out.println(fibo(c));
}
}
}
No comments:
Post a Comment