Thursday, 28 August 2014

Example of using recursive methods.




The task is to get the Fibonacci series printed in a recursive method.

Its output is every number is a total of previous two numbers i.e. 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610



static int Fibonacci(int value)
{
if (value == 0 || value == 1)
return value;
return (Fibonacci(value - 1) + Fibonacci(value - 2));
}


in the above code value represents number of permutations we would like to get this series generated for. The output printed before the code is for 15 permutations.


No comments: