Logic for getting fibonacci series?

Kmandapalli
Posted by Kmandapalli under C# category on | Points: 40 | Views : 1870
static int Fibonacci (int x)
{
Console.WriteLine ("Fibonacci = {0}", x);
if (x <= 1)
{
return x;
}
return Fibonacci (x-1) + Fibonacci (x-2);
}

static void Main( )
{
Console.WriteLine ("Fibonacci = {0}", Fibonacci (5));

// Wait for read one key
Console.ReadKey();
}

Comments or Responses

Login to post response