fibonacci series using function
As we all know,python is an easy to start programming language.
coding program are the most problems given in hiring interviews.
So,lets get started with basic programs.
problem:find the nth element in fibonacci series.
sample input:7
sample output:13
python code:
def fib(n):
if(n==0):
return 0
elif(n==1):
return 1
else:
return fib(n-1)+fib(n-2)
n=int(input('enter an integer value'))
for i in range(0,n+1):
x=fib(i)
print(x)
coding program are the most problems given in hiring interviews.
So,lets get started with basic programs.
problem:find the nth element in fibonacci series.
sample input:7
sample output:13
python code:
def fib(n):
if(n==0):
return 0
elif(n==1):
return 1
else:
return fib(n-1)+fib(n-2)
n=int(input('enter an integer value'))
for i in range(0,n+1):
x=fib(i)
print(x)
Comments
Post a Comment