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

any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above

0 Answers  


Is a pointer a kind of array?

0 Answers  


write the program for maximum of the following numbers? 122,198,290,71,143,325,98

5 Answers  


program to find a smallest number in an array

15 Answers   Microsoft, Sony,


enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }

4 Answers   ME,






write a program of bubble sort using pointer?

3 Answers   TCS,


What is the size of structure pointer in c?

0 Answers  


Why we write conio h in c?

0 Answers  


Where static variables are stored in memory in c?

0 Answers  


Why structure is used in c?

0 Answers  


What is wrong with this program statement? void = 10;

0 Answers  


#ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); }

3 Answers   ADITI,


Categories