Created
August 9, 2012 08:17
-
-
Save masaru-b-cl/3302274 to your computer and use it in GitHub Desktop.
菊池さん考案のフィボナッチ数列なIEnumerable<int>を返す関数
This file contains 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 FibonacciSequence | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var i = 0; | |
foreach (var fib in Fib().Take(11)) | |
{ | |
Console.WriteLine(i + ":" + fib); | |
i++; | |
} | |
} | |
private static IEnumerable<int> Fib() | |
{ | |
var a = 0; | |
var b = 1; | |
yield return a; | |
yield return b; | |
for (; ; ) | |
{ | |
a = a + b; | |
yield return a; | |
b = a + b; | |
yield return b; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment