Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Last active February 6, 2016 19:05
Show Gist options
  • Select an option

  • Save gregjhogan/c9c6d25277e1636497e7 to your computer and use it in GitHub Desktop.

Select an option

Save gregjhogan/c9c6d25277e1636497e7 to your computer and use it in GitHub Desktop.
Fibonacci Sequence Calculator
public class Fibinocci
{
public readonly int N;
public Fibinocci(int n)
{
if (n < 0)
{
throw new Exception("n must be >= 0");
}
this.N = n;
}
public int Calculate()
{
if (this.N == 0)
{
return 0;
}
return Calculate(0, 1, 1);
}
internal int Calculate(int previous, int current, int count)
{
if (count == this.N)
{
return current;
}
return this.Calculate(current, previous + current, ++count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment