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


Please Help Members By Posting Answers For Below Questions

What are inline functions? What is the syntax for defining an inline function?

591


What is the extension of c++?

527


what is data encapsulation in C++?

618


What is object oriented programming (oop)?

635


What is singleton class in c++?

602






Why pointer is used in c++?

627


Write a program which uses Command Line Arguments

642


What do you mean by public protected and private in c++?

609


How much maximum can you allocate in a single call to malloc()?

647


What is the difference between struct and class?

757


What are protected members in c++?

633


Why can templates only be implemented in the header file?

670


What are default parameters? How are they evaluated in c++ function?

677


What is function overloading c++?

580


Why cout is used in c++?

581