Skip to content

Commit 71a10ea

Browse files
Merge pull request #21 from drbalar/fibonacci-c-sharp
Fibonacci question in c#
2 parents 0327578 + e1ab3d2 commit 71a10ea

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

C#/fibonacci.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Return the nth fibonacci number
2+
3+
public static int get_n_fibonacci(int n)
4+
{
5+
int num = n - 1; //Need to decrement by 1 since we are starting from 0
6+
int[] fib = new int[num + 1];
7+
fib[0]= 0;
8+
fib[1]= 1;
9+
for (int i = 2; i <= num;i++)
10+
{
11+
fib[i] = fib[i - 2] + fib[i - 1];
12+
}
13+
return Fib[num];
14+
}

0 commit comments

Comments
 (0)