Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created May 20, 2011 15:11
Show Gist options
  • Save mostlygeek/983117 to your computer and use it in GitHub Desktop.
Save mostlygeek/983117 to your computer and use it in GitHub Desktop.
C# Fibonacci Generator
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