Fibonacci series upto 20 natural numbers using recursion

Fibonacci series upto 20 natural numbers using recursion
SOURCE : FibonaciSeries.java


public class FibonaciSeries {

public static long fibnac(long n){


if((n==1)||(n==2)){
return 1;
}
else return fibnac(n-1)+fibnac(n-2);
}


public static void main(String[] args) {




for(int i=1;i<20;i++){

System.out.println(" "+fibnac(i));

}


}

}



INPUT

print Fibonacci Series from natural number up to 20



OUTPUT

1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181








Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment