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
Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?
Explain pass by value and pass by reference.
What are register variables?
What is rtti in c++?
What is a container class? What are the types of container classes in c++?
What is abstract class in c++?
Explain queue. How it can be implemented?
What is functions syntax in c++?
What is setiosflags c++?
Difference between inline functions and macros?
How do you define/declare constants in c++?
what is a class? Explain with an example.
How many keywords are used in c++?
What is the use of string in c++?
What is the auto keyword good for in c++?