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 |
void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result for all case
What is the difference between exit() and _exit()?
print pattern 1 1 33 33 555 555 77777777 555 555 33 33 1 1
Can you think of a way when a program crashed before reaching main? If yes how?
from which concept of 'c', the static member function of 'c++' has came?
The __________ attribute is used to announce variables based on definitions of columns in a table?
What are the advantages of union?
#include<stdio.h> main(0 { printf("\n %d %d %d",sizeof(3),sizeof("3"),sizeof(3)); }
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
What's wrong with "char *p = malloc(10);" ?
Does sprintf put null character?
Simplify the program segment if X = B then C ← true else C ← false