 # Solution URI Online Judge | 1029 Fibonacci, How Many Calls? Easy Programming Solutions & Tutorials Learn easy method of programming solutions and best tutorials

Solution URI Online Judge | 1029 Fibonacci

## Solution URI Online Judge | 1029 Fibonacci, How Many Calls?

First learn how to solve problem :

Define the problem. Diagnose the situation so that your focus is on the problem, not just its symptoms. Helpful problemsolving techniques include using flowcharts to identify the expected steps of a process and cause-and-effect diagrams to define and analyze root causes.

### Solution in C:

#include

int counter, call;

int fib(int n)

{

if(n == 0){

call++;

return 0;

}else if(n == 1){

call++;

counter++;

return 1;

}else{

call++;

return fib(n – 1) + fib(n – 2);//call recursively

}

}

int main()

{

int n, i, x, res;

scanf(“%d”, &n);

for (i = 0; i < n; ++i)

{

counter = 0;

call = 0;

scanf(“%d”, &x);

res = fib(x);

printf(“fib(%d) = %d calls = %d\n”, x, call – 1, counter);

}

return 0;

}