Write the program for fibonacci in c++?

Answer Posted / darren chang

int fib(int input)
{
if(input==0)
return 0;
if((input==1)||(input==2))
return 1;
else
return fib(input-1)+fib(input-2);
}

Is This Answer Correct ?    10 Yes 31 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which one between if-else and switch is more efficient?

606


Which is the best c++ compiler for beginners?

564


How static variables and local variablesare similar and dissimilar?

567


write a corrected statement so that the instruction will work properly. if (4 < x < 11) y = 2 * x;

1518


What is virtual destructor ans explain its use?

608






How do I exit turbo c++?

587


What are the advantage of using register variables?

643


Explain the difference between static and dynamic binding of functions?

557


Are vectors faster than arrays?

571


Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?

2016


What is the difference between equal to (==) and assignment operator (=)?

581


Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?

706


What does the following do: for(;;) ; a) Illegal b) Loops forever c) Ignored by compiler...not illegal

704


Which operator cannot be overloaded c++?

593


What is bubble sort c++?

577