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 prototype in c++ with example?
Which is better c++ or java?
What do you mean by function and operator overloading in c++?
Explain how a pointer to function can be declared in C++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
State two differences between C and C++.
What is different in C++, compare with unix?
Can I run c program in turbo c++?
What is a breakpoint?
What is null and void pointer?
What will happen if a pointer is deleted twice?
How do you traverse a btree in backward in-order?
what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?
Name four predefined macros.
Explain the concept of dynamic allocation of memory?