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
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 |
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 |
Differentiate between functions getch() and getche().
What is putchar() function?
What is calloc malloc realloc in c?
difference between memcpy and strcpy
I have a varargs function which accepts a float parameter?
Explain what is output redirection?
post new interiew question and aptitude test papers
What are pointers?
0 Answers Accenture, Tavant Technologies, Zensar,
x=2,y=6,z=6 x=y==z; printf(%d",x)
13 Answers Bharat, Cisco, HCL, TCS,
how to compare two strings without using strcmp() function??
will the program compile? int i; scanf(ā%dā,i); printf(ā%dā,i);
What is array of structure in c?