51
1
using System;
2
using System.Collections.Generic;
3
4
/*
5
Fibonacci numbers and sequences
6
https://en.wikipedia.org/wiki/Fibonacci_number
7
*/
8
public class Fibonacci
9
{
10
// this method computes the n-th Fibonacci number
11
// e.g. for n = 8, the Fibonacci number is 21
12
public int getFibonacciNumber(int n) {
13
if (n == 0 || n == 1) {
14
return n;
15
}
16
else {
17
return getFibonacciNumber(n - 1) + getFibonacciNumber(n - 2);
18
}
19
}
20
21
// this method computes the n-th Fibonacci sequence
22
// e.g. for n = 8, the Fibonacci sequence is [1, 1, 2, 3, 5, 8, 13, 21]
23
public List<int> getFibonacciSequence(int n) {
24
List<int> f_series = new List<int>();
Cached Result