Fibonacci series by recursion in python by R4R Team

Fibonacci series-
- fibonacci series is a sequence of numbers in which each number is obtain by the sum of two previous numbers, starting from 0 and 1.

Fibonacci series upto n term-

0 1 1 2 3 5 8 13 21 34 ..............n

Recursion-
- function call itself again an again it known as recursion,.


program-

def func(n,a,b):
if n==0:
print("n")
return
s=a+b
print(s,end=" ")
func(n-1,b,s)

#fibonacci series upto 10 term
func(10,-1,1)

#fibonacci series upto 20 term
func(20,-1,1)


output-

0 1 1 2 3 5 8 13 21 34

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


-In this program, we create a function called as 'func()' which doing recursion and determine next upcoming term and print next term so that we get required fibonacci series.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!