Fibonacci numbers in C#
Example for versions
Microsoft Visual C# 2008,
gmcs 2.0.1
This example uses recursive definition of Fibonacci numbers.
using System;
class Program
{
static long Fibonacci(int n)
{
if (n < 3)
return 1;
else
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
static void Main(string[] args)
{
for (int i = 1; i < 17; i++)
Console.Write("{0}, ", Fibonacci(i));
Console.WriteLine("...");
}
}
Comments
]]>blog comments powered by Disqus
]]>