i want explaination about the program and its stack reprasetaion

fibbo(int n)
{
if(n==1 or n==0)
return n;
else
return fibbo(n-1)+fibbo(n-2);
}
main()
{
fibbo(6);
}

Answers were Sorted based on User's Feedback



i want explaination about the program and its stack reprasetaion fibbo(int n) { if(n==1 or n==0..

Answer / abdur rab

#include <stdio.h>

int fibonacci ( int nNumber )
{
if ( ( nNumber == 0 ) || ( nNumber == 1 ) ) return
( nNumber );
return fibonacci ( nNumber -1 ) + fibonacci (
nNumber - 2 ) ;
}


int main ( int argc, char* argv[] )
{
printf ( "\n The Fibnoci value :%d", fibonacci (
5 ) );
return ( 1 );


Other than the logical or, everyting is perfect, the
function will recursivel bubble down and for this value it
ud become like this if u copy this to a notepad, with
formating, it ud be easy to understand

4 +
3

3 + 2
2 + 1

2 + 1 1 + 0
1 + 0 ( will return 1 )

1 + 0 ( all others will return 1 )

Is This Answer Correct ?    1 Yes 0 No

i want explaination about the program and its stack reprasetaion fibbo(int n) { if(n==1 or n==0..

Answer / vignesh1988i

here the return function will give an error message or it
will only take the first function (ie) fibbo(n-1) since
after return this is the first recursive function
called.... so this altast return 1 to the main program....
that's all.... as for as i know this will be the
procedure...... and then the "or" must not be used .. only
logicalOR must be used ||.........

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

What are valid signatures for the Main function?

0 Answers  


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

0 Answers  


"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

0 Answers  


Reverse the part of the number which is present from position i to j. Print the new number.[without using the array] eg: num=789876 i=2 j=5 778986

2 Answers  


State the difference between x3 and x[3].

0 Answers   Aricent,






What is the difference between mpi and openmp?

0 Answers  


In C, What is the #line used for?

2 Answers  


Write a C program to multiply tho numbers without using arithmetic operator (+, -, *, /).

1 Answers  


What is difference between union All statement and Union?

0 Answers  


why do we use pointer instead directly acessing the data?

2 Answers  


What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }

9 Answers   CTS, Wipro,


How can I read a binary data file properly?

0 Answers  


Categories