Created
June 3, 2020 08:56
-
-
Save bhaveshmunot1/6367d71f4be0f98ca979c8557046e17a to your computer and use it in GitHub Desktop.
Find N-th Fibonacci number using recursion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fibonacci(int n) { | |
if (n == 1) { | |
return 0; | |
} | |
if (n == 2) { | |
return 1; | |
} | |
int n_minus_1_fibonacci = fibonacci(n-1); | |
int n_minus_2_fibonacci = fibonacci(n-2); | |
return n_minus_1_fibonacci + n_minus_2_fibonacci; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment