Fibonacci não recursivo
unknown
python
a year ago
266 B
16
Indexable
n = int(input())
def fibo(n):
if n == 0:
return 0
if n == 1:
return 1
ultimo = 0 + 1
penultimo = 0
i = 2
while i < n:
aux = ultimo
ultimo = ultimo + penultimo
penultimo = aux
i += 1
return ultimo + penultimo
print(fibo(n))
Editor is loading...
Leave a Comment