diff --git a/algorithms/CSharp/src/Maths/fibonacci-series.cs b/algorithms/CSharp/src/Maths/fibonacci-series.cs new file mode 100644 index 00000000..1e287aee --- /dev/null +++ b/algorithms/CSharp/src/Maths/fibonacci-series.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace Algorithms.Maths { + public class fibonacci_series { + // Fibonacci Series using Recursion and Memoization + public static int[] FibonacciSeries(int n) { + var memo = new Dictionary(); + var result = new int[n]; + for (int i = 0; i < n; i++) { + result[i] = Fibonacci(i, memo); + } + + return result; + } + + private static int Fibonacci(int n, Dictionary memo) { + if (n == 0 || n == 1) { + return n; + } + + if (memo.ContainsKey(n)) { + return memo[n]; + } + + memo[n] = Fibonacci(n - 1, memo) + Fibonacci(n - 2, memo); + return memo[n]; + } + } + +} \ No newline at end of file diff --git a/algorithms/CSharp/test/Number-Theory/fibonacci-seires.cs b/algorithms/CSharp/test/Number-Theory/fibonacci-seires.cs new file mode 100644 index 00000000..cbb40e77 --- /dev/null +++ b/algorithms/CSharp/test/Number-Theory/fibonacci-seires.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace Algorithms.Tests.Number_Theory { + [TestFixture] + public class fibonacci_seires { + + [TestCase(34, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34)] + + + + + public void CalculateFibonacciSeriesTest(int value, int[] expected) { + var result = Algorithms.Maths.fibonacci_series.FibonacciSeries(value); + Assert.AreEqual(expected, result); + } + + } +} \ No newline at end of file