Computer Programming || Gaming || Technology || ai

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


uri-online judge

 

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?

uri online judge 1002 solution . Man blogs on what is programming language computer programming for beginners computer programming c++ computer programming pdf computer programming courses basic computer programming what is programming used for c programming.

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;

}

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *




Calender

October 2020
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031