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

Write about the access privileges in c++ and also mention about its default access level?

1068


what is a class? Explain with an example.

1142


List the merits and demerits of declaring a nested class in C++?

1033


When should we use container classes instead of arrays?

1029


What is do..while loops structure?

1157


Do vectors start at 0?

995


Why should you learn c++?

1030


When you overload member functions, in what ways must they differ?

1053


Explain the difference between c++ and java.

1121


Which software is used to run c++ program?

1011


Explain about vectors in c ++?

1035


Define the operators that can be used with a pointer.

1065


What is the difference between #define debug 0 and #undef debug?

1193


What is recursion?

2201


Does c++ cost money?

999