Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created January 4, 2014 00:37
Show Gist options
  • Save mikedugan/8249709 to your computer and use it in GitHub Desktop.
Save mikedugan/8249709 to your computer and use it in GitHub Desktop.
iterative C# implementation of a Fibonacci sequence
public static int Fibonacci(int n)
{
int a = 0;
int b = 1;
// In N steps compute Fibonacci sequence iteratively.
for (int i = 0; i < n; i++)
{
int temp = a;
a = b;
b = temp + b;
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment