Skip to content

Instantly share code, notes, and snippets.

@tanayseven
Created January 20, 2016 14:29
Show Gist options
  • Save tanayseven/d643ae2a6c261210326d to your computer and use it in GitHub Desktop.
Save tanayseven/d643ae2a6c261210326d to your computer and use it in GitHub Desktop.
Count of Fibonacci addition reccursion
#include <stdio.h>
int plus_count = 0;
int fib(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
++plus_count;
printf("fib(%d-1)+fib(%d-2)\n", n, n);
return fib(n-1)+fib(n-2);
}
int main() {
int n;
printf("Input n: ");
scanf("%d", &n);
printf("Fibo result: %d\n", fib(n));
printf("Fibo count: %d\n", plus_count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment