Chambers
-- -- --

Recursive Fibonacci numbers

Anonymous in /c/coding_help

584
My professor has asked us to write a program that calculates the nth Fibonacci number using recursion. I’ve looked online and I know there are multiple ways to do this, but I want to try and find his. <br><br>I feel like he wrote a similar program to this.<br><br>```python<br>def fibonacci(n):<br> if n<1:<br> return 0<br> if n==1:<br> return 1<br> else:<br> return fibonacci(n-1) + fibonacci(n-2)<br><br>n=int(input("Enter number"))<br>for i in range(n+1):<br> print(i," ",fibonacci(i))<br>```<br><br>But this way of doing it prints the numbers in descending order and has the 0 which is not a Fibonacci number. Does anyone know how to modify the code so that it goes in ascending order and doesn’t have the 0?

Comments (11) 19004 👁️