Created
August 17, 2012 00:29
-
-
Save kevinmeredith/3374793 to your computer and use it in GitHub Desktop.
Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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