Created
May 20, 2011 15:11
-
-
Save mostlygeek/983117 to your computer and use it in GitHub Desktop.
C# Fibonacci Generator
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; | |
namespace CSharpFib | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
foreach (ulong x in Fibber(5)) { | |
Console.WriteLine(x); | |
} | |
} | |
public static IEnumerable Fibber(int c) | |
{ | |
ulong a, b, o; | |
a = o = 0; | |
b = 1; | |
do { | |
yield return a; | |
o = a; | |
a = b; | |
b = o + b; | |
} while (--c > 0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment