Print out the first n values of the Fibonacci sequence c#. The sequence starts with 0 and 1, and all the next numbers are the sum of the two previous ones. Use a While-Loop! code example
Example: c# fibonacci sequence
using System;
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));
}
}
}