codereverser said:try this algo (not in any specific language):
Code:function fib(n) { if n <= 1 : return n else return fib(n-1) + fib(n-2); }
There u goAceMcCloud said:Here...this might help...
int fib(int n)
{
if (n <= 1)
return n;
else
return fib(n-1)+fib(n-2);
}
Lord Nemesis said:^^ LOL... read what viralbug and hammerhead said again. Just give it a try and you will get it.
Alright let me give a hint...
You already have an example of a recursive program posted here, so if you want to print the actual sequence in the ascending order, all you need to do is to tweak the recursion such that it generates the fibonacci number in the ascending order and print the number at each step. You already know the first two numbers of the sequence are 0 and 1. so use them for starting the recursion.
Next if you want to control how many numbers of the sequence you print, just use an additional 'counter' parameter in the function which you decrement every time you enter the recursive function. make the function return when the counter reaches 0.