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);
}
Answer Posted / 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 |
Post New Answer View All Answers
Why do we use c for the speed of light?
What is a void * in c?
In C language what is a 'dangling pointer'?
Is array a primitive data type in c?
What is 'bus error'?
Explain what is the benefit of using an enum rather than a #define constant?
is it possible to create your own header files?
Why can arithmetic operations not be performed on void pointers?
Do you know what are bitwise shift operators in c programming?
How reliable are floating-point comparisons?
How can I swap two values without using a temporary?
how we can make 3d venturing graphics on outer interface
What does %c mean in c?
Write a program for finding factorial of a number.
Explain the use of bit fieild.