In the above link what Vulpes gave, That thread is good one to understand. But Fibonacci Sequence could be generated by two ways: 1. Recursive Aprroach 2. Iterative Approach
The above link generates fibonacci sequence using recursive approach. If you want to generate the same sequence using iterative approach, here is the code:
class Program { 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; }
static void Main() { for (int i = 0; i < 15; i++) { Console.WriteLine(Fibonacci(i)); } } }
Hemant SrivastavaPosted Nov 7, 2012, 5:28 PM
1. Recursive Aprroach
2. Iterative Approach
The above link generates fibonacci sequence using recursive approach. If you want to generate the same sequence using iterative approach, here is the code:
class Program
{
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;
}
static void Main()
{
for (int i = 0; i < 15; i++)
{
Console.WriteLine(Fibonacci(i));
}
}
}
VulpesPosted Nov 7, 2012, 8:31 AM
http://www.c-sharpcorner.com/Forums/Thread/127366/fibonacci-series-pseudocode.aspx