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
What is a singleton c++?
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
Which software is used for c++ programming?
Is sorted c++?
What is a pointer how and when is it used?
What is a try block?
Why do we use constructor?
Is c++ harder than java?
what Is DCS ? what i will get benefit when i did?
On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?
What's the order in which the objects in an array are destructed?
What are built-in functions? What is the syntax for the definition?
What is the exit function in c++?
What is the main function c++?
C is to C++ as 1 is to a) What the heck b) 2 c) 10