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
Write about the access privileges in c++ and also mention about its default access level?
what is a class? Explain with an example.
List the merits and demerits of declaring a nested class in C++?
When should we use container classes instead of arrays?
What is do..while loops structure?
Do vectors start at 0?
Why should you learn c++?
When you overload member functions, in what ways must they differ?
Explain the difference between c++ and java.
Which software is used to run c++ program?
Explain about vectors in c ++?
Define the operators that can be used with a pointer.
What is the difference between #define debug 0 and #undef debug?
What is recursion?
Does c++ cost money?