Fibonaci
what is fibonaci code in c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 7, 2012, 3:31 AM EST
http://www.c-sharpcorner.com/Forums/Thread/127366/fibonacci-series-pseudocode.aspx
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 7, 2012, 12:28 PM EST
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));
}
}
}