Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created August 8, 2012 00:49
Show Gist options
  • Save masaru-b-cl/3291008 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/3291008 to your computer and use it in GitHub Desktop.
Fibonacci
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);
}
}
}
@masaru-b-cl
Copy link
Author

実行結果
0:0
1:1
2:1
3:2
4:3
5:5
6:8
7:13
8:21
9:34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment