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 oldest programming language?

958


What is linked list in c++?

1095


What does I ++ mean in c++?

1045


Define pointers?

1013


What do c++ programmers do?

1018


Do you know what are static and dynamic type checking?

1027


What is data types c++?

969


Is it possible to pass an object of the same class in place of object reference to the copy constructor?

987


Do you need a main function in c++?

1084


What is the this pointer?

1080


What are destructors?

951


What are the advantages of using pointers in a program?

1103


What is null pointer and void pointer?

1017


Is c++ proprietary?

1016


What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

1109