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 stream and its types in c++?

984


What does it mean to declare a member variable as static?

1004


daily Routine of father

1350


Tell me can a pure virtual function have an implementation?

965


What is the role of C++ shorthand's?

1221


int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}

1205


What data encapsulation is in c++?

1047


what is Member Functions in Classes?

1108


Can you help me with this one? Make a program that when a user inputed a Product Name, it will display its price, and when the user inputed the quantity of the inputed product, it will show its total price. The output must be like this: Product Name: Price: Quantity: Total Price: ..this is the list of products to be inputed: Cellphone - 1500 Washing Machine - 5200 Television - 6000 Refrigirator - 8000 Oven - 2000 Computer - 11000 thanks..:D

3599


What are disadvantages of pointers?

984


What is the use of dot in c++?

1023


How do you invoke a base member function from a derived class in which you’ve overridden that function?

1063


Explain the virtual inheritance in c++.

1000


Does c++ vector allocate memory?

937


What are the benefits of c++?

981