Created
January 20, 2016 14:29
-
-
Save tanayseven/d643ae2a6c261210326d to your computer and use it in GitHub Desktop.
Count of Fibonacci addition reccursion
This file contains hidden or 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
#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