Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

nth fibonacci number

def fib(n):
    if(n<0):
        print("Invalid input")
    elif(n==0):
        return 0
    elif(n==1) or (n==2):
        return 1
    else:
        return fib(n-1)+fib(n-2)
n=int(input())
print(fib(n))
 
PREVIOUS NEXT
Tagged: #nth #fibonacci #number
ADD COMMENT
Topic
Name
5+3 =