Skip to content

Instantly share code, notes, and snippets.

@kevinmeredith
Created August 17, 2012 00:29
Show Gist options
  • Select an option

  • Save kevinmeredith/3374793 to your computer and use it in GitHub Desktop.

Select an option

Save kevinmeredith/3374793 to your computer and use it in GitHub Desktop.
Fibonacci
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fibonacci
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("fibonacci:");
int i;
for (i = 0; i < 10; ++i)
{
Console.WriteLine("fibonacci(" + i + ") = " + fibonacci(i));
}
Console.ReadLine();
}
private static int fibonacci(int n)
{
int sum = 0;
switch(n)
{
case 0:
return sum;
case 1:
return ++sum;
default:
return fibonacci(n-1) + fibonacci(n-2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment