Write the program for fibonacci in c++?
Answer Posted / srinivasan
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
What is the c++ code?
In c++, what is the difference between method overloading and method overriding?
How can you tell what shell you are running on unix system?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
How to allocate memory dynamically for a reference?
What is the best way to declare and define global variables?
Can you pass a vector to a function?
What are stacks? Give an example where they are useful.
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop
How can virtual functions in c++ be implemented?
Explain about Virtual Function in C++?
Why #include is used?
What is c++ used for in games?
When do we use copy constructors?
Why do we use constructor?