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 / terah njehia

#include<iostream>
#include<iomanip>
using namespace std;

int fn1 = 0, fn2 = 1;
int nextfib(int* fib1, int* fib2)
{
long int next = *fib1 + *fib2;
*fib1 = *fib2;
*fib2 = next;
cout<<setw(3)<<next<<endl;
return 0;
}

int main()
{
int n;
cout<<"Enter the value n of fibonacci numbers you want to
print"<<endl;
cin>>n;
int newn = n - 2;
cout<<setw(3)<<fn1<<setw(3)<<fn2;
for (int index = 1; index <= newn; index++){
nextfib(&fn1, &fn2);
}
return 0;
}

Is This Answer Correct ?    11 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a singleton c++?

1046


What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

1163


Which software is used for c++ programming?

1135


Is sorted c++?

1164


What is a pointer how and when is it used?

1146


What is a try block?

1119


Why do we use constructor?

1114


Is c++ harder than java?

1127


what Is DCS ? what i will get benefit when i did?

2414


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

1184


What's the order in which the objects in an array are destructed?

1465


What are built-in functions? What is the syntax for the definition?

1135


What is the exit function in c++?

1028


What is the main function c++?

1172


C is to C++ as 1 is to a) What the heck b) 2 c) 10

1113