Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bhaveshmunot1
Created June 3, 2020 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhaveshmunot1/6367d71f4be0f98ca979c8557046e17a to your computer and use it in GitHub Desktop.
Save bhaveshmunot1/6367d71f4be0f98ca979c8557046e17a to your computer and use it in GitHub Desktop.
Find N-th Fibonacci number using recursion.
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