May 10, 2013

C++ program to print Fibonacci series

#include<iostream.h>
#include<conio.h>
void main()
{
/*FIBONACCI SERIES */
char choice;
do
{
clrscr();
long double num, a=1, b=0, count;
cout<<"ENTER THE NUMBER OF ELEMENTS REQUIRED : ";
cin>>num;
cout<<"\n\n";
for(count=1; count<=num/2;count++)
{
a+=b;
cout<<b << "\t";
b+=a;
cout<<a << "\t";
}
cout<<"\n\nREPEAT THE SAME PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}

OUTPUT

a)
ENTER THE NUMBER OF ELEMENTS REQUIRED : 8
0 1 1 2 3 5 8  13
REPEAT THE SAME PROGRAM? (Y/N) : y

0 comments:

Post a Comment