Calculate Fibonacci sequence using recursive function in C#

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 4117
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();
}

Comments or Responses

Login to post response