Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write the program for fibonacci in c++?

Answer Posted / gobicsk

#include <iostream>
using namespace std;

const int n = 20;
long result[n];

int fibonacci( int m )
{
if( result[m] > 0 )
// We already computed it.
return result[m];

int answer;

if( m == 0 )
answer = 0;
else
if( m == 1 )
answer = 1;
else
answer = fibonacci( m - 1 ) + fibonacci( m - 2 );

// Save answer for re-use.
result[m] = answer;
return answer;
}

int main()
{
fibonacci( n );

cout << "\n Fibonacci Series \n";

for( int i = 0; i <= n; i++ )
cout << "\n Fibonacci(" << i << ") = " << result[i];

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the basic structure of c++ program?

1156


Can union be self referenced?

1216


Write a struct time where integer m, h, s are its members?

1017


which of the following is not an secondary constant a) array b) real c) union

1856


What is the average salary of a c++ programmer?

1067


Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);

1117


Are vectors faster than arrays?

1053


How we can differentiate between a pre and post increment operators during overloading?

1156


Why is c++ considered difficult?

1222


What is :: operator in c++?

1106


Specify different types of decision control statements?

917


What are mutator methods in c++?

1201


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

1083


What are the implicit member functions of class?

1133


How many standards of c++ are there?

1145