5
I’m having problems with the recursive function Fibonacci, in the exercise you ask to print inside the function or even using an auxiliary recursive function, but you can’t print in the main function, I tried everything to print, but they keep repeating, the recursive function Fibonacci I know how to do, just missing the impression, follows the enunciation and ask someone to give me a light.
"The Fibonacci sequence is defined by:
- F0 = 0
- F1 = 1
- Fn = Fn - 1 + Fn - 2, for n > 1
Develop a recursive function that calculates and prints the first n Fibonacci sequence numbers. The function must have the following signature:
int fibonacci (int n);
The function shall print the first n numbers separated by spaces, by example, for n = 10:
0 1 1 2 3 5 8 13 21 34"
Just to say that there are other forms besides recursion: http://answall.com/questions/177138/como-optimizar-essa-fun%C3%A7%C3%A3o-para-sequ%C3%Aancia-de-fibonacci/177269
– Marcus Becker
I just want to make it clear that Fibonacci is an example of where nay whether to use recursion, at least not without some other trick. See the question @Marcusbecker linked above for more details.
– Victor Stafusa
It is mandatory the use of recursion, are test exercises on the content. TMB does not like recursion with Fibonacci, it is very long execution, but it is a course and this is the theme
– Marcelo de Sousa
@Marcelodesousa Yes, I know. My comment above was just to make it clear to some casual visitor that bumping into this question that using recursion in Fibonacci in a simple and straightforward way is not a good idea.
– Victor Stafusa