Print first 5 Fibonacci terms.
Ready — edit the code above and click Run.
using System;
class Program
{
static void Main()
{
int count = 5, a = 0, b = 1;
Console.Write(a + " ");
for (int k = 2; k < count; k++) {
int c = a + b; Console.Write(c + " "); a = b; b = c;
}
}
}
Try solving on your own first, then reveal the official answer.
Iterative Fibonacci O(n).