Fibnocci numbers are the sequence 1,2,3,5,8,13,21,34,55,89,144 ..... etc.
This sequence is known as the Fibonacci series, and is well known in mathematics. Each number is the sum of the previous two.
The C# Code Snippet will calculate a Fibnocci Number by using recursion, i.e. the Fibnocci method calls itself when necessary.
static int Fibonacci (int x) { Console.WriteLine ("x = {0}", x); if (x <= 1) { return 1; } return Fibonacci (x-1) + Fibonacci (x-2); } static void Main( ) { Console.WriteLine ("Fibonacci no. = {0}", Fibonacci (5)); Console.ReadKey(); }
Hope this code snippet would be useful to all members.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|