Fibonacci Series
This algorithm finds the fibonacci series. In this algorithm the next number is found by adding up the two numbers before it.
Example of fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
public static int[] Fibonacci(int count)
{
int[] numbers = new int[count];
if (count > 1)
{
numbers[0] = 0;
numbers[1] = 1;
}
int i = 2;
while (i < count)
{
numbers[i] = numbers[i - 1] + numbers[i - 2];
++i;
}
return numbers;
}
Example
int[] fibonacciNumbers = Fibonacci(10);
Output
0
1
1
2
3
5
8
13
21
34