Created
August 8, 2012 00:49
-
-
Save masaru-b-cl/3291008 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; | |
namespace Fibonacci | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var i in Enumerable.Range(0, 10)) | |
{ | |
Console.WriteLine(i + ":" + Fib(i)); | |
} | |
} | |
private static int Fib(int n) | |
{ | |
return n == 0 | |
? 0 | |
: n == 1 | |
? 1 | |
: Fib(n - 2) + Fib(n - 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果
0:0
1:1
2:1
3:2
4:3
5:5
6:8
7:13
8:21
9:34