class Program
{
static void Main(string[] args)
{
int fib = 20;
fib = computeFibonacci(fib); Console.WriteLine(fib);
fib = 20;
fib = computeFibonacciRecursive(fib); Console.WriteLine(fib);
}
private static int computeFibonacciRecursive(int n)
{
if (n <= 1)
{
return n;
}
else
{
return computeFibonacciRecursive(n - 1) + computeFibonacciRecursive(n - 2); //<------
}
}
private static int computeFibonacci(int n)
{
int a = 1, b = 1;
for (int i = 3; i <= n; i++)
{
int c = a + b;
a = b;
b = c;
Console.WriteLine("b is= " + b);
}
return b;
}
}
|