An iterative algorithm for Fibonacci numbers

后端 未结 13 1056
野性不改
野性不改 2020-11-28 10:37

I am interested in an iterative algorithm for Fibonacci numbers, so I found the formula on wiki...it looks straight forward so I tried it in Python...it doesn\'t have a prob

相关标签:
13条回答
  • 2020-11-28 11:30

    Another possible approach:

    a=0
    b=1
    d=[a,b]
    n=int(input("Enter a number"))
    i=2
    while i<n:
        e=d[-1]+d[-2]
        d.append(e)
        i+=1
    print("Fibonacci series of {} is {}".format(n,d))
    
    0 讨论(0)
提交回复
热议问题